parent
4cd3bf18e0
commit
f39d4978c3
|
@ -122,7 +122,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object message = getAttribute(requestAttributes, "javax.servlet.error.message");
|
Object message = getAttribute(requestAttributes, "javax.servlet.error.message");
|
||||||
if (message != null || errorAttributes.get("message") == null) {
|
if ((message != null || errorAttributes.get("message") == null) && !(error instanceof BindingResult)) {
|
||||||
errorAttributes.put("message", message == null ? "No message available"
|
errorAttributes.put("message", message == null ? "No message available"
|
||||||
: message);
|
: message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||||
import org.springframework.boot.test.TestRestTemplate;
|
import org.springframework.boot.test.TestRestTemplate;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.RequestEntity;
|
import org.springframework.http.RequestEntity;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -41,6 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.servlet.View;
|
import org.springframework.web.servlet.View;
|
||||||
import org.springframework.web.servlet.view.AbstractView;
|
import org.springframework.web.servlet.view.AbstractView;
|
||||||
|
@ -73,8 +75,21 @@ public class BasicErrorControllerIntegrationTests {
|
||||||
"http://localhost:" + this.port, Map.class);
|
"http://localhost:" + this.port, Map.class);
|
||||||
assertThat(entity.getBody().toString(), endsWith("status=500, "
|
assertThat(entity.getBody().toString(), endsWith("status=500, "
|
||||||
+ "error=Internal Server Error, "
|
+ "error=Internal Server Error, "
|
||||||
+ "exception=java.lang.IllegalStateException, " + "message=Expected!, "
|
+ "exception=java.lang.IllegalStateException, "
|
||||||
+ "path=/}"));
|
+ "message=Server Error, " + "path=/}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public void testErrorForAnnotatedException() throws Exception {
|
||||||
|
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||||
|
"http://localhost:" + this.port + "/annotated", Map.class);
|
||||||
|
assertThat(
|
||||||
|
entity.getBody().toString(),
|
||||||
|
endsWith("status=400, "
|
||||||
|
+ "error=Bad Request, "
|
||||||
|
+ "exception=org.springframework.boot.autoconfigure.web.BasicErrorControllerIntegrationTests$TestConfiguration$Errors$ExpectedException, "
|
||||||
|
+ "message=Expected!, " + "path=/annotated}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -124,6 +139,11 @@ public class BasicErrorControllerIntegrationTests {
|
||||||
throw new IllegalStateException("Expected!");
|
throw new IllegalStateException("Expected!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/annotated")
|
||||||
|
public String annotated() {
|
||||||
|
throw new ExpectedException();
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping("/bind")
|
@RequestMapping("/bind")
|
||||||
public String bind(HttpServletRequest request) throws Exception {
|
public String bind(HttpServletRequest request) throws Exception {
|
||||||
BindException error = new BindException(this, "test");
|
BindException error = new BindException(this, "test");
|
||||||
|
@ -131,6 +151,12 @@ public class BasicErrorControllerIntegrationTests {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Expected!")
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
private static class ExpectedException extends RuntimeException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue