Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoconfigure include stacktrace #727

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package org.zalando.problem.spring.web.autoconfigure;

import org.apiguardian.api.API;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zalando.problem.jackson.ProblemModule;
import org.zalando.problem.violations.ConstraintViolationProblemModule;

import static org.apiguardian.api.API.Status.INTERNAL;
import static org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute.ALWAYS;

/**
* Registers Problem Jackson modules when {@link WebMvcAutoConfiguration} is
Expand All @@ -22,11 +25,14 @@
public class ProblemJacksonAutoConfiguration {

@Bean
public ProblemModule problemModule() {
return new ProblemModule();
@ConditionalOnMissingBean(ProblemModule.class)
public ProblemModule problemModule(ObjectProvider<ServerProperties> serverProperties) {
ServerProperties props = serverProperties.getIfAvailable();
return new ProblemModule().withStackTraces(props != null && props.getError().getIncludeStacktrace().equals(ALWAYS));
}

@Bean
@ConditionalOnMissingBean(ConstraintViolationProblemModule.class)
public ConstraintViolationProblemModule constraintViolationProblemModule() {
return new ConstraintViolationProblemModule();
}
Expand Down