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