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

Unable to rely on express error handler to get contextualized error #4696

Closed
saulogt opened this issue Apr 2, 2018 · 1 comment
Closed

Comments

@saulogt
Copy link
Contributor

saulogt commented Apr 2, 2018

In previous versions of parse-server,(<2.3), I was able to handle generic errors in express.js error handler, but that capability has been removed (~ one year ago) by this PR 145a1fe.

It basically replaces next(err) by log.error(err.message, err) assuming that calling the default error handler is useless. But it missed an important point... The logger don't have the request, but the express handler does. It's extremely important in my case to track which request path and parameters caused the error.

Since then I'm using patched forks of parse server that calls next(err) besides the logger.
I strongly believe it's the right way to go.

Steps to reproduce

  1. Implement an express error handler:
app.use(function(err, req, res, next) {
    console.error(err.message || err, 'path:', req.path);
    // Do whatever you want to get the contect of the error
})
  1. Run the server and generate an error by getting an invalid object, for example:
curl --request GET \
  --url http://localhost:1337/parse/classes/Whatever/blablabla \
  --header 'x-parse-application-id: <appid>' \
  --header 'x-parse-master-key: <masterkey if needed>' 

Expected Results

The error handler is called and the error is logged in the console with the path.

Actual Outcome

Nothing happens

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 2.7.4
    • Operating System: MacOS and heroku dyno
    • Hardware: Heroku Dyno X2
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Localhost and Heroku
  • Database

    • MongoDB version: 3.2.17 (WiredTiger)
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab

More context on this: #2841

@flovilmart
Copy link
Contributor

If you check the details of the PR, it’s actually on purpose that the next(err) call has been removed.

Closing as this is the intended behavior. Feel free to open a PR that preserves the current behavior and enable you to achieve what you’re expecting.

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

No branches or pull requests

2 participants