question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better HttpException class

See original GitHub issue

Feature 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:closed
  • Created 4 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Sep 6, 2019

@nartc I am actually using a similar model, it is a filter that catches all HttpException and converts them into ApolloError to be nicely formatted in the GraphQL response. The problem that I noticed is that the Stacktrace 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.

0reactions
lock[bot]commented, Feb 1, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HttpException Class (System.Web) - Microsoft Learn
The HttpException class is an HTTP-specific exception class that enables ASP.NET to generate exception information. For more information about throwing and ...
Read more >
HTTPException (Java Platform SE 7 ) - Oracle Help Center
public class HTTPException extends ProtocolException. The HTTPException exception represents a XML/HTTP fault. Since there is no standard format for faults ...
Read more >
What Java exception class to use for HTTP errors?
HttpException class that is probably a good fit. If you do need a custom exception class for this I would think java.io.
Read more >
Handling Errors - FastAPI
FastAPI has its own HTTPException . And FastAPI's HTTPException error class inherits from Starlette's HTTPException error class. The only difference, is that ...
Read more >
Exception filters | NestJS - A progressive Node.js framework
Nest provides a built-in HttpException class, exposed from the @nestjs/common package. For typical HTTP REST/GraphQL API based applications, it's best practice ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found