Skip to content

Fix for unhandled undefined config #4334

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 7 commits into from
Nov 11, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Routers/PublicAPIRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class PublicAPIRouter extends PromiseRouter {
const appId = req.params.appId;
const config = Config.get(appId);

if (!config.publicServerURL) {
if (!config || !config.publicServerURL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.');
}

Copy link
Contributor

@flovilmart flovilmart Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, didn't see that initially. @bryandel take flovilmart's suggestion for the proper error to report.

return this.missingPublicServerURL();
}

Expand All @@ -40,7 +40,7 @@ export class PublicAPIRouter extends PromiseRouter {
const appId = req.params.appId;
const config = Config.get(appId);

if (!config.publicServerURL) {
if (!config || !config.publicServerURL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

return this.missingPublicServerURL();
}

Expand All @@ -66,7 +66,7 @@ export class PublicAPIRouter extends PromiseRouter {
changePassword(req) {
return new Promise((resolve, reject) => {
const config = Config.get(req.query.id);
if (!config.publicServerURL) {
if (!config || !config.publicServerURL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

return resolve({
status: 404,
text: 'Not found.'
Expand All @@ -89,7 +89,7 @@ export class PublicAPIRouter extends PromiseRouter {

const config = req.config;

if (!config.publicServerURL) {
if (!config || !config.publicServerURL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return this.missingPublicServerURL();
}

Expand All @@ -114,7 +114,7 @@ export class PublicAPIRouter extends PromiseRouter {

const config = req.config;

if (!config.publicServerURL) {
if (!config || !config.publicServerURL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return this.missingPublicServerURL();
}

Expand Down