Fix User Error in Async API Endpoint (#9911)
This commit is contained in:
parent
d59858e32c
commit
00179adcaa
3 changed files with 11 additions and 1 deletions
|
@ -54,7 +54,7 @@ export async function apiResolver(
|
|||
apiRes.json = data => sendJson(apiRes, data)
|
||||
|
||||
const resolver = interopDefault(resolverModule)
|
||||
resolver(req, res)
|
||||
await resolver(req, res)
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError) {
|
||||
sendError(apiRes, err.statusCode, err.message)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export default async (req, res) => {
|
||||
throw new Error('User error')
|
||||
}
|
|
@ -63,6 +63,13 @@ function runTests(dev = false) {
|
|||
expect(text).toBe('Internal Server Error')
|
||||
})
|
||||
|
||||
it('should throw Internal Server Error (async)', async () => {
|
||||
const res = await fetchViaHTTP(appPort, '/api/user-error-async', null, {})
|
||||
const text = await res.text()
|
||||
expect(res.status).toBe(500)
|
||||
expect(text).toBe('Internal Server Error')
|
||||
})
|
||||
|
||||
it('should parse JSON body', async () => {
|
||||
const data = await fetchViaHTTP(appPort, '/api/parse', null, {
|
||||
method: 'POST',
|
||||
|
|
Loading…
Reference in a new issue