-
Notifications
You must be signed in to change notification settings - Fork 72
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
Improve location and property_id error response to return 400 status instead of 500 server error #4884
Improve location and property_id error response to return 400 status instead of 500 server error #4884
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Passing run #7739 ↗︎
Details:
Review all test suite changes for PR #4884 ↗︎ |
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.
This worked as expected! I just made some small recommendations to clean up the tests a bit and a way to handle errors in the lookupGeolcation
call
); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.error(error); |
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.
Add this line before the console.error to disable the lint error
console.error(error); | |
// eslint-disable-next-line no-console | |
console.error(error); |
console.error(error); | ||
res | ||
.status(400) // 400 Bad Request. Malformed request. | ||
.send(error.message); |
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.
You can do this instead of checking if error
is an instance of Error
and then you could fallback to still return an error message instead of just the empty return
res
.status(400) // 400 Bad Request. Malformed request.
.send(
error instanceof Error ? error.message : "An unknown error occurred."
);
try { | ||
await lookupGeolocation(req); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
expect(error.message).toMatch( | ||
"Provided location (US-NewYork) query parameter is not in ISO 3166 format." | ||
); | ||
} else { | ||
expect(typeof error).toBe(Error); | ||
} | ||
} |
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.
You can simplify these checks using Jest's toThrow
syntax
await expect(lookupGeolocation(req)).rejects.toThrow(
"Provided location (US-NewYork) query parameter is not in ISO 3166 format."
);
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.
I think for this one it throws an Error
object and not a string. So I think this may not work, will check it now and comment back.
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.
I was wrong, this works perfectly, I like it, thanks!
Closes PROD-2035
Description Of Changes
Improved validation error messages for
fides.js
.Code Changes
geolocation
param is provided but is invalid, e.g. `Invalid request: geolocation "foo" is invalid, must supply an ISO 3166-2 location codeproperty_id
param, and forIS_OVERLAY_ENABLED
,IS_PREFETCH_ENABLED
andFIDES_STRING
environment variables.Steps to Confirm
geolocation
param with wrong location text infides.js
, so it checks the format.property_id
param withoutgeolocation
param.Pre-Merge Checklist
CHANGELOG.md