Better HttpException class
See original GitHub issueFeature Request
Is your feature request related to a problem?
The current problem with the included HttpException is that they are wrapped up to act as an Error
class, even though they are not implemented as excepted. Moreover, the object containing the Http exception is duplicated under two different keys. This problem arises especially when you throw the Exception which shows a stack trace not clear as below:
Error: [object Object],
at ContactService.getContacts(...)
...
Describe the solution you’d like
I would like to have an HttpException easy to trace, easy to customize or swap out of the box (same approach as the other NestJS tools). There exists great library for HTTP exceptions such as @hapi/boom, which can do the job and be used under the hood.
Teachability, Documentation, Adoption, Migration Strategy
This is a change under the hood of the implementation of the base class HTTPException.
What is the motivation / use case for changing the behavior?
As stated before, hard to track or customize. Let’s take this example:
@Injectable()
export class ContactService {
public async getContacts(id: string): Promise<Contact[]> {
// [...] some external calls
const [res, otherRes] = await Promise.all([req, otherReq]);
if (res.result.type === 'Failed') {
// this exception will have a trace to here with [Object object]
// which can be understood only by looking at the code
throw new NotFoundException(`${res.result.message}`);
}
// [...] some other logic
}
}
System info
NestJS: 6.5.3 Node.js: 12.9.0 OS: Windows_NT x64 10.0.17763
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (7 by maintainers)
@nartc I am actually using a similar model, it is a filter that catches all
HttpException
and converts them intoApolloError
to be nicely formatted in the GraphQL response. The problem that I noticed is that theStacktrace
of these thrown errors are not correctly serialized. Let me investigate what would be our goal in terms of Error traceability and then I will come back and tell you more about what is the actual problem.This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.