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.

Problem with disabling stacktrace

See original GitHub issue

My code is:

@Configuration
public class ProblemJsonConfiguration {
    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper().registerModule(new ProblemModule().withStackTraces(false));
    }
}
@ControllerAdvice
public class ExceptionHandler implements ProblemHandling { ... }

and response always contains field stackTrace:

{
  "cause": null,
  "stackTrace": [
    {
      "methodName": "resolveArgument",
      "fileName": "AbstractNamedValueMethodArgumentResolver.java",
      "lineNumber": 123,
      "className": "org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver",
      "nativeMethod": false
    },...
  ],
  "type": "about:blank",
  "title": "Bad Request",
  "status": "BAD_REQUEST",
  "detail": "Failed to convert value of type [java.lang.String] to required type ...",
  "instance": null,
  "parameters": {},
  "message": "Bad Request: Failed to convert value of type [java.lang.String] to required type ...",
  "localizedMessage": "Bad Request: Failed to convert value of type [java.lang.String] to required type ...",
  "suppressed": []
}

I followed steps on https://github.com/zalando/problem-spring-web/blob/master/README.md#stack-traces-and-causal-chains

Tried this:

@ControllerAdvice
class ExceptionHandling implements ProblemHandling {
    @Override
    public boolean isCausalChainsEnabled() {
        return false;
    }
}

and this: server.error.include-stacktrace=NEVER

There is no way to disable stactTrace. Am I doing something wrong?

BTW, Is there possibility to rename and disable some fields?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
kschulstcommented, Nov 15, 2017

FWIW, I just encountered the same issue (using spring boot 2 M6). Ended up with registering modules like this::

   @Bean
    public Jackson2ObjectMapperBuilderCustomizer problemObjectMapperModules() {
        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.modules(
                new ProblemModule(),
                new ConstraintViolationProblemModule()
        );
    }
1reaction
rajatul26commented, Jan 16, 2019

I was also facing the same issue with Spring boot(2.0.2.RELEASE) MVC based application. If you are extending WebMvcConfigurerAdapter or implementing WebMvcConfigurer interface to customize the default behaviour just override the configureMessageConverters method of the same by adding the following code.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    log.debug("Configuring custom HttpMessageConverters.");
    ObjectMapper mapper = Jackson2ObjectMapperBuilder.json()
            .modules(new ProblemModule(), new ConstraintViolationProblemModule()).build();

    converters.add(new MappingJackson2HttpMessageConverter(mapper));
}

It worked for me.

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable the default stacktrace error response in Jetty
We received a PenTest finding stating that the stack trace given from the 400 "Unable to Parse" Jetty error (below) gives the attacker...
Read more >
Disable stacktraces in Tomcat's error pages to make it ready ...
Disable stacktraces in Tomcat's error pages to make it ready for production ... I am running a Tomcat on AWS. The problem is...
Read more >
How to avoid the detailed stack trace from showing up ... - IBM
For some security consideration, customer usually asks to hide detailed stack trace to avoid sensitive information to be showed. For example, customer wants...
Read more >
How to Enable/Disable the Stack Trace - Mura Docs v7.0
If you wish to disable this feature, simply append /?showtrace=0 to the URL, and the stack trace should disappear after reloading your browser....
Read more >
Hide stack trace thrown by Tomcat while deploying ...
Hide the stack trace thrown by Tomcat (Application Server) when something goes wrong or there is an error in some configuration file while...
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