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

Enable express error handler #4697

Merged
merged 13 commits into from
Jul 17, 2018
Merged

Enable express error handler #4697

merged 13 commits into from
Jul 17, 2018

Conversation

saulogt
Copy link
Contributor

@saulogt saulogt commented Apr 3, 2018

This PR is to enable the default express error handler on all cases if config param enableExpressErrorHandler is truthy

I'm solving the issue #4696 without changing the current default behavior.

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

Can you add a test. I don’t believe req.config has those paramss

@codecov
Copy link

codecov bot commented Apr 3, 2018

Codecov Report

Merging #4697 into master will decrease coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4697      +/-   ##
==========================================
- Coverage   92.96%   92.91%   -0.06%     
==========================================
  Files         119      119              
  Lines        8828     8830       +2     
==========================================
- Hits         8207     8204       -3     
- Misses        621      626       +5
Impacted Files Coverage Δ
src/Options/Definitions.js 100% <ø> (ø) ⬆️
src/middlewares.js 98.19% <100%> (+0.02%) ⬆️
src/Adapters/Auth/meetup.js 84.21% <0%> (-5.27%) ⬇️
src/RestWrite.js 93.24% <0%> (-0.55%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 97.2% <0%> (-0.09%) ⬇️

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 ced6b76...af9e6ce. Read the comment docs.

@saulogt
Copy link
Contributor Author

saulogt commented Apr 5, 2018

@flovilmart, That option enableExpressErrorHandler didn't exist. I introduced that just to alow (restore) the default express handler.
Test added.

@saulogt
Copy link
Contributor Author

saulogt commented May 30, 2018

@flovilmart , is it still missing something?
I added the test as you requested.

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

Some nits in the tests please

app.use(function (err, req, res, next) {
next
lastError = err
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you follow style and conventions and add the ; at the expected places please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

const rp = require('request-promise');

describe('Enable express error handler', () => {
beforeEach((done) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why you need this, as you create a new server separately. Please remove if not required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Really not needed

const serverUrl = "http://localhost:12667/parse"
const appId = "anOtherTestApp";
const masterKey = "anOtherTestMasterKey";
let server;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems written to, but never read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used to store the server to be closed later

.then(() => {
                  server.close(done);
                });

server = app.listen(12667);

app.use(function (err, req, res, next) {
next
Copy link
Contributor

Choose a reason for hiding this comment

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

This line as no effect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just to silence the linter.
The function needs to have 4 arguments to be recognized as an error handler, but I don't want to call next again

body: { someField: "blablabla"},
json: true
})
.then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you keep the alignment consistent with the rest of the code? Better, use async / await

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keeping the alignment :)

fail('Should throw error');
})
.catch(e => {
expect(e).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do some tests on the expected error here? As well as lastError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@saulogt
Copy link
Contributor Author

saulogt commented Jul 11, 2018

Hey @flovilmart , Sorry about the delay.
I hope it's good now

@flovilmart
Copy link
Contributor

Not sure why but the build fails on the CI.

@saulogt
Copy link
Contributor Author

saulogt commented Jul 17, 2018

@flovilmart , CI fixed now. It was a recent change on master that got merged into my branch.
ae1a822

@flovilmart
Copy link
Contributor

Perfect thanks!

@flovilmart flovilmart merged commit b22947d into parse-community:master Jul 17, 2018
flovilmart pushed a commit that referenced this pull request Aug 12, 2018
* Propagate error to express handler in all situations

* Call the default error handler if `enableExpressErrorHandler` is truthy

* Updating options interface and definitions

* Testing express error handler

* Test spec fixes

* Fix test
flovilmart pushed a commit that referenced this pull request Aug 12, 2018
* Propagate error to express handler in all situations

* Call the default error handler if `enableExpressErrorHandler` is truthy

* Updating options interface and definitions

* Testing express error handler

* Test spec fixes

* Fix test
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* Propagate error to express handler in all situations

* Call the default error handler if `enableExpressErrorHandler` is truthy

* Updating options interface and definitions

* Testing express error handler

* Test spec fixes

* Fix test
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