Unverified Commit 00179adc authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix User Error in Async API Endpoint (#9911)

parent d59858e3
...@@ -54,7 +54,7 @@ export async function apiResolver( ...@@ -54,7 +54,7 @@ export async function apiResolver(
apiRes.json = data => sendJson(apiRes, data) apiRes.json = data => sendJson(apiRes, data)
const resolver = interopDefault(resolverModule) const resolver = interopDefault(resolverModule)
resolver(req, res) await resolver(req, res)
} catch (err) { } catch (err) {
if (err instanceof ApiError) { if (err instanceof ApiError) {
sendError(apiRes, err.statusCode, err.message) sendError(apiRes, err.statusCode, err.message)
......
export default async (req, res) => {
throw new Error('User error')
}
...@@ -63,6 +63,13 @@ function runTests(dev = false) { ...@@ -63,6 +63,13 @@ function runTests(dev = false) {
expect(text).toBe('Internal Server Error') 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 () => { it('should parse JSON body', async () => {
const data = await fetchViaHTTP(appPort, '/api/parse', null, { const data = await fetchViaHTTP(appPort, '/api/parse', null, {
method: 'POST', method: 'POST',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment