Skip to content
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

GraphQL: Improve session token error messages #5753

Conversation

douglasmuraoka
Copy link
Contributor

Fixes the session token related error messages during GraphQL operations. If any authentication error were thrown, it was not correctly handled by the GraphQL express middleware, and ended responding the request with a JSON parsing error.

Fixes the session token related error messages during GraphQL operations. If any authentication error were thrown, it was not correctly handled by the GraphQL express middleware, and ended responding the request with a JSON parsing error.
app.use(this.config.graphQLPath, (err, req, res, next) => {
if (err && err instanceof Parse.Error) {
res.json(
new ApolloError({
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to use this.parseGraphQLSchema.handleError() function (https://github.com/parse-community/parse-server/blob/master/src/GraphQL/ParseGraphQLSchema.js#L102) or at least the same logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've refactored the conversion of the Parse.Error to ApolloError. Since the handleError method includes some logging and throws the error, I thought it was better to just refactor the middleware to use this conversion and set the error as response, because that's all we need for now.

@codecov
Copy link

codecov bot commented Jul 2, 2019

Codecov Report

Merging #5753 into master will increase coverage by 0.04%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5753      +/-   ##
==========================================
+ Coverage   93.62%   93.66%   +0.04%     
==========================================
  Files         145      146       +1     
  Lines       10211    10236      +25     
==========================================
+ Hits         9560     9588      +28     
+ Misses        651      648       -3
Impacted Files Coverage Δ
src/GraphQL/ParseGraphQLSchema.js 94.73% <100%> (+2.93%) ⬆️
src/GraphQL/ParseGraphQLServer.js 97.22% <100%> (+0.07%) ⬆️
src/GraphQL/parseGraphQLUtils.js 75% <75%> (ø)
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.82% <0%> (-0.09%) ⬇️
src/Adapters/Auth/apple-signin.js
src/Adapters/Auth/apple.js 100% <0%> (ø)
src/Routers/ClassesRouter.js 96.7% <0%> (+0.07%) ⬆️
src/Adapters/Auth/index.js 92.85% <0%> (+0.12%) ⬆️
src/RestQuery.js 95.63% <0%> (+0.15%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c40310...2f57df5. Read the comment docs.

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

I am wondering if wouldn't be better just add the middlewares.handleParseErrors like the REST api does here instead of using this whole thing.

Also, can you please add some test cases?

@@ -319,6 +319,9 @@ export function handleParseErrors(err, req, res, next) {
case Parse.Error.OBJECT_NOT_FOUND:
httpStatus = 404;
break;
case Parse.Error.INVALID_SESSION_TOKEN:
Copy link
Member

Choose a reason for hiding this comment

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

humm.. I'm not sure... I think it can break some apps. Let's just leave 400 as it was before.

@davimacedo davimacedo merged commit f91034a into parse-community:master Jul 12, 2019
@douglasmuraoka douglasmuraoka deleted the graphql_session_token_error_message branch July 15, 2019 13:13
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* GraphQL: Improve session token error message

Fixes the session token related error messages during GraphQL operations. If any authentication error were thrown, it was not correctly handled by the GraphQL express middleware, and ended responding the request with a JSON parsing error.

* Refactor handleError usage

* Use handleParseErrors middleware to handle invalid session token error

* fix: Status code 400 when session token is invalid

* fix: Undo handleParseErrors middleware change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants