-
Notifications
You must be signed in to change notification settings - Fork 0
FEAT-1: Add weather app backend functionality to sample app #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are several potential issues in the given code.
Misplaced comment: At the top of the
api.get('/')
interaction, there's a note that this is a first response to calculate a client's geolocation from its IP. However, directly under that, the client IP address is being anonymized. The anonymization process may strip some valuable data needed to ascertain geolocation accurately.Error handling: There're no catch blocks for promise rejections (e.g., weather API failures), which could lead to unhandled promise rejections and crash the server if an error event isn't properly caught. To prevent such issues, promises should ideally have a
.catch()
block attached to handle errors gracefully.Weather location hard-coded: The logic seems to assume that all clients are located in Toronto by default ("43.7001", "-79.4163", "America/Toronto"). This might not be representative of the actual client base, especially considering that previous code attempts to calculate location based on an IP address.
GeoIP confusion: In
api.get('/geolocate')
, 'geoip(req.ip)is being used instead of
requestCoordsFromIP(req.ip). Since the earlier imports include
requestCoordsFromIP`, it looks like maybe 'geoip' was a typo.Lack of validation: The '/weather' endpoint doesn't have any validation before hitting the 'weather' function. The latitude, longitude, and timezone query parameters need to have some format check or validation before use.
Redundancy: Looking at this code snippet, the app tries to get geolocation data twice - once when loading the root route
/
, and again when the/geolocate
endpoint is hit. If getting the geolocation data is costly in time or resources, duplicating the activity might present performance issues.Variable name mismatch: There's a mismatch in checking the key "region" in one case and using it as "coords.regionName" later. This might be a typo which can lead to
undefined
value.Incomplete response: If
queryParams.lat
,queryParams.lon
,queryParams.timezone
are not provided in the '/weather' endpoint, an error message is sent immediately without terminating the function - potentially leading to additional code execution and errors.Stripped IP address for geolocation: The IP is anonymized before being used to determine geolocation. If too much information is stripped, geolocation may fail or be inaccurate.