-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Enable express error handler #4697
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
Changes from 9 commits
049c123
5d147af
5b5e70a
b16f981
7f34824
ab61255
5ce34bb
a83d33c
ee0431b
0c8c493
5716caf
25dffe2
af9e6ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const ParseServer = require("../src/index"); | ||
const express = require('express'); | ||
const rp = require('request-promise'); | ||
|
||
describe('Enable express error handler', () => { | ||
beforeEach((done) => { | ||
reconfigureServer({ | ||
enableExpressErrorHandler: true, | ||
schemaCacheTTL: 30000 | ||
}).then(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should call the default handler in case of error, like updating a non existing object', done => { | ||
const serverUrl = "http://localhost:12667/parse" | ||
const appId = "anOtherTestApp"; | ||
const masterKey = "anOtherTestMasterKey"; | ||
let server; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems written to, but never read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used to store the server to be closed later
|
||
|
||
let lastError; | ||
|
||
const parseServer = ParseServer.ParseServer(Object.assign({}, | ||
defaultConfiguration, { | ||
appId: appId, | ||
masterKey: masterKey, | ||
serverURL: serverUrl, | ||
enableExpressErrorHandler: true, | ||
__indexBuildCompletionCallbackForTests: promise => { | ||
promise | ||
.then(() => { | ||
expect(Parse.applicationId).toEqual("anOtherTestApp"); | ||
const app = express(); | ||
app.use('/parse', parseServer); | ||
|
||
server = app.listen(12667); | ||
|
||
app.use(function (err, req, res, next) { | ||
next | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line as no effect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just to silence the linter. |
||
lastError = err | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
rp({ | ||
method: 'PUT', | ||
uri: serverUrl + '/classes/AnyClass/nonExistingId', | ||
headers: { | ||
'X-Parse-Application-Id': appId, | ||
'X-Parse-Master-Key': masterKey | ||
}, | ||
body: { someField: "blablabla"}, | ||
json: true | ||
}) | ||
.then(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping the alignment :) |
||
fail('Should throw error'); | ||
}) | ||
.catch(e => { | ||
expect(e).toBeDefined(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
expect(lastError).toBeDefined(); | ||
}) | ||
.then(() => { | ||
server.close(done); | ||
}); | ||
}) | ||
}} | ||
)); | ||
}); | ||
|
||
}); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Really not needed