Skip to content

throw Parse.Error in Custom Authentication Module doesn't get treated as Parse.Error #6467

Closed
@appxplore-tech

Description

@appxplore-tech

Issue Description

I write my own custom Authentication Module due to some features that are not available here and I did throw some Parse.Error in the custom Authentication Module and I expect that I did receive the ParseError in my client instead of Internal server error code.

Steps to reproduce

  1. Create a Latest Parse-Server using Parse-Express-Example(I tried those version before: 4.1.0, 3.10.0, 3.8.0, 3.6.0)
  2. import my npm package with command : npm install parse-server-auth-google
  3. in the index.js, replace the default google auth module with my auth module:
    "google":{module:"parse-server-auth-google"}
  4. start the parse-server
  5. call the post request as below to trigger the function:
    url: https://<>/parse/users
    method: POST
    Body: {"authData":{"google":{"id":"111"}}}
    Headers: (Normal Headers as usual to call parse-server, for eg. X-Parse-Application-Id, Content-Type)

Expected Results

Receive a response with HTTP-Status: 404 with Body as below:

{
    "code": 101,
    "error": "Facebook auth is invalid for this user."
}

Actual Outcome

Receive a response with HTTP-Status: 500 with Body as below:

{
    "code": 1,
    "message": "Internal server error."
}

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : [3.6.0,3.8.0,3.10.0,4.1.0]
    • Operating System: [Ubuntu Server 16.04.6]
    • Hardware: [AWS r4.large]
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): [AWS]
  • Database

    • MongoDB version: [4.0.13]
    • Storage engine: [WiredTiger]
    • Hardware: [2 Replica Set]
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): [AWS EC2]

Logs/Trace

Below are the logs that shown in my pm2. I found that during my own module file, the error i throw is still a Parse.Error type, but when it comes to middlewares.js, the function handleParseErrors will not treated it as a Parse.Error type.

48|appxplo | {"method":"POST","url":"/parse/users","headers":{"x-parse-application-id":"SICXfgOJNhYtBZUiM6Ua5IP1Pxwo4qJfgn8rJ7yS","x-parse-rest-api-key":"57y6F7BZwyaqn9YWYdKJgLeGTItAKukIrpOYYipL","content-type":"application/json","x-parse-installation-id":"c8cf2c87-3341-41c1-b386-25ab1b11839f","user-agent":"PostmanRuntime/7.22.0","accept":"*/*","cache-control":"no-cache","postman-token":"84f5dc58-bed3-4e94-99a8-89facb2e83d2","host":"xxxx.xxxx.xxxx.xxxx:xxxx","accept-encoding":"gzip, deflate, br","content-length":"36","connection":"keep-alive"},"body":{"authData":{"google":{"id":"111"}}},"level":"verbose","message":"REQUEST for [POST] /parse/users: {\n  \"authData\": {\n    \"google\": {\n      \"id\": \"111\"\n    }\n  }\n}"}
48|appxplo | google error:  { ParseError: 101 Google auth is invalid for this user.
48|appxplo |     at Object.validateAuthData (/mnt/data/parse/appxplore-testapp/node_modules/parse-server-auth-google/index.js:45:17)
48|appxplo |     at /mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/Adapters/Auth/index.js:93:20
48|appxplo |     at Object.keys.map.provider (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:361:12)
48|appxplo |     at Array.map (<anonymous>)
48|appxplo |     at RestWrite.handleAuthDataValidation (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:350:45)
48|appxplo |     at findUsersWithAuthData.then (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:496:17)
48|appxplo |     at <anonymous>
48|appxplo |     at process._tickDomainCallback (internal/process/next_tick.js:228:7) message: 'Google auth is invalid for this user.', code: 101 }
48|appxplo | is error instanceof Parse.Error:  true
48|appxplo | [handleParseErrors], error:  { ParseError: 101 Google auth is invalid for this user.
48|appxplo |     at Object.validateAuthData (/mnt/data/parse/appxplore-testapp/node_modules/parse-server-auth-google/index.js:45:17)
48|appxplo |     at /mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/Adapters/Auth/index.js:93:20
48|appxplo |     at Object.keys.map.provider (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:361:12)
48|appxplo |     at Array.map (<anonymous>)
48|appxplo |     at RestWrite.handleAuthDataValidation (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:350:45)
48|appxplo |     at findUsersWithAuthData.then (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:496:17)
48|appxplo |     at <anonymous>
48|appxplo |     at process._tickDomainCallback (internal/process/next_tick.js:228:7) message: 'Google auth is invalid for this user.', code: 101 }
48|appxplo | [handleParseErrors], err instanceof _node.default.Error:  false
48|appxplo | {"message":"Uncaught internal server error.Google auth is invalid for this user.","code":101,"level":"error","stack":"ParseError: 101 Google auth is invalid for this user.\n    at Object.validateAuthData (/mnt/data/parse/appxplore-testapp/node_modules/parse-server-auth-google/index.js:45:17)\n    at /mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/Adapters/Auth/index.js:93:20\n    at Object.keys.map.provider (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:361:12)\n    at Array.map (<anonymous>)\n    at RestWrite.handleAuthDataValidation (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:350:45)\n    at findUsersWithAuthData.then (/mnt/data/parse/appxplore-testapp/node_modules/parse-server/lib/RestWrite.js:496:17)\n    at <anonymous>\n    at process._tickDomainCallback (internal/process/next_tick.js:228:7)"}

Please let me know if I'm doing it wrong. thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions