Fix for unhandled undefined config#4334
Conversation
When an invalid application id is passed either for reset/change password or email verification, config.get returns undefined. This causes internal server.
Codecov Report
@@ Coverage Diff @@
## master #4334 +/- ##
==========================================
+ Coverage 92.52% 92.54% +0.01%
==========================================
Files 118 118
Lines 8258 8273 +15
==========================================
+ Hits 7641 7656 +15
Misses 617 617
Continue to review full report at Codecov.
|
|
Nice catch. The standard 'Not found.' & '404' response seems ok, @flovilmart think we're good using the existing |
|
We should probably throw if Config.get(appId) don’t return anything no? |
|
Something like this? throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'appId not found');or maybe |
|
What do we usually throw when making a request with an invalid appId? Unauthorized I guess .) |
|
No specific cases come to mind actually, just Simple and to the point. Both of those other refs just throw errors, the latter uses |
src/Routers/PublicAPIRouter.js
Outdated
There was a problem hiding this comment.
Would you be willing to update this to handle !config separately? We would like to throw an exception rather than return a standard 404. Something like this should do
if (!config) {
throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'appId does not exist in config.');
}There was a problem hiding this comment.
following in middleware.js if appId can't be found, this should be
if (!config) {
const error = new Error();
error.status = 403;
error.message = "unauthorized";
throw error;
}
The error will be handled by the PromiseRouter and transformed in to the proper response.
There was a problem hiding this comment.
Ahh, didn't see that initially. @bryandel take flovilmart's suggestion for the proper error to report.
src/Routers/PublicAPIRouter.js
Outdated
src/Routers/PublicAPIRouter.js
Outdated
src/Routers/PublicAPIRouter.js
Outdated
src/Routers/PublicAPIRouter.js
Outdated
…p id Also, added a missing semicolon
|
Thank you for the suggestions. I have changed the implementation and also added tests for the code coverage. But it seems in the last build a different test has failed
|
|
@bryandel thanks again for the PR! |
…munity#4334) * Fix for unhandled undefined config When an invalid application id is passed either for reset/change password or email verification, config.get returns undefined. This causes internal server. * Throwing a 403 exception instead of returning a 404 for an invalid app id Also, added a missing semicolon * Fix indent issues * Fix invalid colon to semicolon * Fix space and indent issues * Tests for the fix for unhandled undefined config
When an invalid application id is passed either for reset/change password or email verification, config.get returns undefined. This causes internal server.