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 data for all problem exceptions

See original GitHub issue

Hi!

I want to add different values to all exceptions. For example zipkin traceId.

I have added:

@Configuration
class SpringDataRestConfiguration extends RepositoryRestConfigurerAdapter {

  @Override
  public void configureJacksonObjectMapper(ObjectMapper objectMapper) {
    objectMapper
        .registerModule(new ProblemModule())
        .registerModule(new ConstraintViolationProblemModule());
  }
}

but when I try to override methods in:

@ControllerAdvice
class GlobalExceptionHandler implements ProblemHandling {
}

I end up with getting the full problem serialized cause, stackTrace, etc.

I must have misunderstood anything about the customization. But do you have any good way to add custom data and how to do the customization?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cbornetcommented, Jun 17, 2019

Maybe adding a toProblemBuilder() method in Problem would help (forcing implementations to implement it) ?

1reaction
whiskeysierracommented, Aug 3, 2022

Exactly. No, there is no good workaround to me knowledge at least. Custom JSON post-processor using Jackson + Spring, maybe. But it won’t be nice either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Custom Data to Exceptions -- Visual Studio Magazine
You can add additional information to any Exception object to help you debug your application when something goes horribly wrong.
Read more >
Implement Custom Exceptions in Java: Why, When and How
Learn 4 best practices for custom exceptions in Java. Understand when and how to use them in your application.
Read more >
Should we use custom exceptions in Python? | by Marcin Kozak
recommends using custom exceptions when one creates an interface or a library, as this helps diagnose problems that have occurred in the code....
Read more >
Custom errors, extending Error - The Modern JavaScript Tutorial
Look at Wrapping exceptions example. All the exceptions-related code there does nothing good. It just bloats the code. The rule of thumb: Never ......
Read more >
Best Practices for exceptions - .NET - Microsoft Learn
Ensure that exception data is available when code executes remotely ... When you create user-defined exceptions, ensure that the metadata for the ...
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