Skip to content

Commit

Permalink
Use instance field for ProblemDetail in ErrorResponse's
Browse files Browse the repository at this point in the history
Closes gh-32644
  • Loading branch information
rstoyanchev committed May 13, 2024
1 parent 8b6a54c commit 5288504
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ default HttpHeaders getHeaders() {
* Return the body for the response, formatted as an RFC 7807
* {@link ProblemDetail} whose {@link ProblemDetail#getStatus() status}
* should match the response status.
* <p><strong>Note:</strong> The returned {@code ProblemDetail} may be
* updated before the response is rendered, e.g. via
* {@link #updateAndGetBody(MessageSource, Locale)}. Therefore, implementing
* methods should use an instance field, and should not re-create the
* {@code ProblemDetail} on every call, nor use a static variable.
*/
ProblemDetail getBody();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,14 +37,17 @@
@SuppressWarnings("serial")
public class AsyncRequestTimeoutException extends RuntimeException implements ErrorResponse {

private final ProblemDetail body = ProblemDetail.forStatus(getStatusCode());


@Override
public HttpStatusCode getStatusCode() {
return HttpStatus.SERVICE_UNAVAILABLE;
}

@Override
public ProblemDetail getBody() {
return ProblemDetail.forStatus(getStatusCode());
return this.body;
}

}

0 comments on commit 5288504

Please sign in to comment.