|
30 | 30 | * {@link #reason} that should be returned.
|
31 | 31 | *
|
32 | 32 | * <p>The status code is applied to the HTTP response when the handler
|
33 |
| - * method is invoked, or whenever said exception is thrown. |
| 33 | + * method is invoked. |
| 34 | + * |
| 35 | + * <p><strong>Note:</strong> when using this annotation on an exception class, |
| 36 | + * or when setting the {@code reason} attribute of the annotation, |
| 37 | + * the {@code HttpServletResponse.sendError} method will be used. |
| 38 | + * |
| 39 | + * With {@code HttpServletResponse.sendError}, the response is considered |
| 40 | + * complete and should not be written to any further. |
| 41 | + * Furthermore servlet container will typically write an HTML error page |
| 42 | + * therefore making the use of a reason unsuitable for REST APIs. |
| 43 | + * For such cases prefer the use of {@link org.springframework.http.ResponseEntity} |
| 44 | + * as a return type and avoid {@code ResponseStatus} altogether. |
34 | 45 | *
|
35 | 46 | * @author Arjen Poutsma
|
36 | 47 | * @author Sam Brannen
|
37 | 48 | * @see org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver
|
| 49 | + * @see javax.servlet.http.HttpServletResponse#sendError(int, String) |
38 | 50 | * @since 3.0
|
39 | 51 | */
|
40 | 52 | @Target({ElementType.TYPE, ElementType.METHOD})
|
|
54 | 66 | * typically be changed to something more appropriate.
|
55 | 67 | * @since 4.2
|
56 | 68 | * @see javax.servlet.http.HttpServletResponse#setStatus(int)
|
| 69 | + * @see javax.servlet.http.HttpServletResponse#sendError(int) |
57 | 70 | */
|
58 | 71 | @AliasFor("value")
|
59 | 72 | HttpStatus code() default HttpStatus.INTERNAL_SERVER_ERROR;
|
60 | 73 |
|
61 | 74 | /**
|
62 | 75 | * The <em>reason</em> to be used for the response.
|
63 |
| - * <p><strong>Note:</strong> due to the use of |
64 |
| - * {@code HttpServletResponse.sendError(int, String)}, the response will be |
65 |
| - * considered complete and should not be written to any further. Furthermore |
66 |
| - * servlet container will typically write an HTML error page therefore making |
67 |
| - * the use of a reason unsuitable for REST APIs. For such cases prefer |
68 |
| - * sending error details in the body of the response. |
69 | 76 | * @see javax.servlet.http.HttpServletResponse#sendError(int, String)
|
70 | 77 | */
|
71 | 78 | String reason() default "";
|
|
0 commit comments