The new decorator function.
import { Controller, ControllerBase, ErrorHandler, GET, IHttpRequest, IHttpResponse } from '@egomobile/http-server'
@Controller()
export default class MyController extends ControllerBase {
@GET()
async index(request: IHttpRequest, response: IHttpResponse) {
throw new Error('Something went wrong!')
}
@ErrorHandler() // mark that method as default error handler
// inside that controller
async handleError(error: any, request: IHttpRequest, response: IHttpResponse) {
const errorMessage = Buffer.from('ERROR: ' + String(error), 'utf8')
response.writeHead(500, {
'Content-Length': String(errorMessage.length)
})
response.write(errorMessage)
response.end()
}
}
Generated using TypeDoc
Add a method of a controller as an error handler.