Commit fce7e4ea authored by Lukáš Huvar's avatar Lukáš Huvar Committed by Joe Haddad

Avoid sending user errors to client (#8005)

* Avoid sending user error to client Closes #7526

* Small improvments

* Update sending errors
parent 34a9cddf
......@@ -49,7 +49,8 @@ export async function apiResolver(
if (e instanceof ApiError) {
sendError(res, e.statusCode, e.message)
} else {
sendError(res, 500, e.message)
console.error(e)
sendError(res, 500, 'Internal Server Error')
}
}
}
......@@ -226,7 +227,7 @@ export function sendError(
) {
res.statusCode = statusCode
res.statusMessage = message
res.end()
res.end(message)
}
interface LazyProps {
......
......@@ -313,7 +313,7 @@ export default class Server {
}
}
apiResolver(
await apiResolver(
req,
res,
params,
......
export default (req, res) => {
throw new Error('User error')
}
......@@ -53,6 +53,13 @@ function runTests (serverless = false) {
expect(json).toEqual({ error: 'Server error!' })
})
it('should throw Internal Server Error', async () => {
const res = await fetchViaHTTP(appPort, '/api/user-error', 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',
......
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