Throwing classes derived from ApiBuilder.ApiResponse is not working correctly
CherryDT opened this issue · comments
David Trapp commented
-
Expected behaviour: If an error is
instanceof ApiBuilder.ApiResponse
, it should work the same as if it is exactly that class. -
What actually happens: If an error class is inheriting from
ApiBuilder.ApiResponse
, it no longer functions like a response object but instead results in anerrorMessage
with a JSON representation of the error.
class NotFoundError extends ApiBuilder.ApiResponse {
constructor (message = 'Not found') {
super(JSON.stringify({ error: message }), { 'Content-Type': 'application/json' }, 404)
}
}
// This doesn't work
throw new NotFoundError()
// This works
throw new ApiBuilder.ApiResponse(JSON.stringify({ error: 'Not found' }), { 'Content-Type': 'application/json' }, 404)
// This is true, so why does it not work?
console.log(new NotFoundError() instanceof ApiBuilder.ApiResponse)