|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -19,11 +19,12 @@ package org.springframework.web.server; |
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
|
|
|
|
import org.springframework.web.method.HandlerMethod; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Exception for errors that fit response status 500 (bad request) for use in |
|
|
|
* Exception for an {@link HttpStatus#INTERNAL_SERVER_ERROR} that exposes extra |
|
|
|
* Spring Web applications. The exception provides additional fields (e.g. |
|
|
|
* information about a controller method that failed, or a controller method |
|
|
|
* an optional {@link MethodParameter} if related to the error). |
|
|
|
* argument that could not be resolved. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @since 5.0 |
|
|
|
* @since 5.0 |
|
|
|
@ -31,6 +32,9 @@ import org.springframework.lang.Nullable; |
|
|
|
@SuppressWarnings("serial") |
|
|
|
@SuppressWarnings("serial") |
|
|
|
public class ServerErrorException extends ResponseStatusException { |
|
|
|
public class ServerErrorException extends ResponseStatusException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
private final HandlerMethod handlerMethod; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private final MethodParameter parameter; |
|
|
|
private final MethodParameter parameter; |
|
|
|
|
|
|
|
|
|
|
|
@ -39,27 +43,60 @@ public class ServerErrorException extends ResponseStatusException { |
|
|
|
* Constructor with an explanation only. |
|
|
|
* Constructor with an explanation only. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ServerErrorException(String reason) { |
|
|
|
public ServerErrorException(String reason) { |
|
|
|
this(reason, null, null); |
|
|
|
super(HttpStatus.INTERNAL_SERVER_ERROR, reason, null); |
|
|
|
|
|
|
|
this.handlerMethod = null; |
|
|
|
|
|
|
|
this.parameter = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Constructor for a 500 error linked to a specific {@code MethodParameter}. |
|
|
|
* Constructor with a reason and root cause. |
|
|
|
|
|
|
|
* @since 5.0.5 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ServerErrorException(String reason, MethodParameter parameter) { |
|
|
|
public ServerErrorException(String reason, Throwable cause) { |
|
|
|
this(reason, parameter, null); |
|
|
|
super(HttpStatus.INTERNAL_SERVER_ERROR, reason, cause); |
|
|
|
|
|
|
|
this.handlerMethod = null; |
|
|
|
|
|
|
|
this.parameter = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Constructor for a 500 error with a root cause. |
|
|
|
* Constructor for a 500 error with a {@link MethodParameter}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ServerErrorException(String reason, @Nullable MethodParameter parameter, @Nullable Throwable cause) { |
|
|
|
public ServerErrorException(String reason, MethodParameter parameter, @Nullable Throwable cause) { |
|
|
|
super(HttpStatus.INTERNAL_SERVER_ERROR, reason, cause); |
|
|
|
super(HttpStatus.INTERNAL_SERVER_ERROR, reason, cause); |
|
|
|
|
|
|
|
this.handlerMethod = null; |
|
|
|
this.parameter = parameter; |
|
|
|
this.parameter = parameter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Constructor for a 500 error with a root cause. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public ServerErrorException(String reason, HandlerMethod handlerMethod, @Nullable Throwable cause) { |
|
|
|
|
|
|
|
super(HttpStatus.INTERNAL_SERVER_ERROR, reason, cause); |
|
|
|
|
|
|
|
this.handlerMethod = handlerMethod; |
|
|
|
|
|
|
|
this.parameter = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Constructor for a 500 error linked to a specific {@code MethodParameter}. |
|
|
|
|
|
|
|
* @deprecated in favor of {@link #ServerErrorException(String, MethodParameter, Throwable)} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
|
|
|
|
public ServerErrorException(String reason, MethodParameter parameter) { |
|
|
|
|
|
|
|
this(reason, parameter, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the controller method associated with the error, if any. |
|
|
|
|
|
|
|
* @since 5.0.5 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
public HandlerMethod getHandlerMethod() { |
|
|
|
|
|
|
|
return this.handlerMethod; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the {@code MethodParameter} associated with this error, if any. |
|
|
|
* Return the controller method argument associated with this error, if any. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public MethodParameter getMethodParameter() { |
|
|
|
public MethodParameter getMethodParameter() { |
|
|
|
|