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.

Custom Exception Handler

See original GitHub issue

Is your feature request related to a problem? Please describe. Thanks for the great package. Now I want to response the error based on some custom exceptions I threw.

Describe the solution you’d like It should expose the default spec-compliant formatError function as: https://github.com/graphql/graphql-js/blob/master/src/error/formatError.js Then it should allow to pass a custom formatError function to handle the error in the schema constructor.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
namnmcommented, Nov 1, 2018

Yes, your idea has basically covered the case. And I think we need to expose the default error handler too.

public class MyExceptionHandler
{
    public QueryError HandleException(ExceptionContext ctx)
    {
        // We need to expose the default exception handler function as a static helper or something
        // So we can get the default QueryError and modify it instead of manually craft a new one
        var res = DefaultExceptionHandler.HandleException(ctx);
        // In this default QueryError it already has the context info such as path, line number...
        // We only want to modify the error message though
        // TODO modify res here based on the exception
        //
        return res;
    }
}
1reaction
michaelstaibcommented, Nov 1, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a Custom Exception in Java
Learn how to define custom exceptions in Java. ... Learn the basics of exception handling in Java as well as some best and...
Read more >
Get Started with Custom Error Handling in Spring Boot (Java)
This approach involves defining a custom exception carrying the HTTP status to use, and all the data required to describe the error that ......
Read more >
Java Custom Exception
Basically, Java custom exceptions are used to customize the exception according to user need. Consider the example 1 in which InvalidAgeException class extends ......
Read more >
Setting a custom exception handler
You can set an exception handler to customize exception handling in rule conditions and actions. When you implement the CustomExceptionHandler API, ...
Read more >
User-defined Custom Exception in Java
Basically, Java custom exceptions are used to customize the exception according to user needs. In simple words, we can say that a User-Defined...
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