Allow custom ProblemDetail in ErrorResponse.Builder
Closes gh-30568
This commit is contained in:
parent
2e43412a82
commit
dcba9475ba
|
|
@ -53,13 +53,11 @@ final class DefaultErrorResponseBuilder implements ErrorResponse.Builder {
|
|||
private Object[] detailMessageArguments;
|
||||
|
||||
|
||||
DefaultErrorResponseBuilder(Throwable ex, HttpStatusCode statusCode, String detail) {
|
||||
DefaultErrorResponseBuilder(Throwable ex, ProblemDetail problemDetail) {
|
||||
Assert.notNull(ex, "Throwable is required");
|
||||
Assert.notNull(statusCode, "HttpStatusCode is required");
|
||||
Assert.notNull(detail, "`detail` is required");
|
||||
this.exception = ex;
|
||||
this.statusCode = statusCode;
|
||||
this.problemDetail = ProblemDetail.forStatusAndDetail(statusCode, detail);
|
||||
this.statusCode = HttpStatusCode.valueOf(problemDetail.getStatus());
|
||||
this.problemDetail = problemDetail;
|
||||
this.typeMessageCode = ErrorResponse.getDefaultTypeMessageCode(ex.getClass());
|
||||
this.titleMessageCode = ErrorResponse.getDefaultTitleMessageCode(ex.getClass());
|
||||
this.detailMessageCode = ErrorResponse.getDefaultDetailMessageCode(ex.getClass(), null);
|
||||
|
|
|
|||
|
|
@ -205,7 +205,16 @@ public interface ErrorResponse {
|
|||
* by a {@link MessageSource} lookup with {@link #getDetailMessageCode()}
|
||||
*/
|
||||
static Builder builder(Throwable ex, HttpStatusCode statusCode, String detail) {
|
||||
return new DefaultErrorResponseBuilder(ex, statusCode, detail);
|
||||
return builder(ex, ProblemDetail.forStatusAndDetail(statusCode, detail));
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant of {@link #builder(Throwable, HttpStatusCode, String)} for use
|
||||
* with a custom {@link ProblemDetail} instance.
|
||||
* @since 6.1
|
||||
*/
|
||||
static Builder builder(Throwable ex, ProblemDetail problemDetail) {
|
||||
return new DefaultErrorResponseBuilder(ex, problemDetail);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue