ErrorResponse support in Spring MVC exception hierarchy
All Spring MVC exceptions from spring-web, now implement ErrorResponse and expose HTTP error response information, including an RFC 7807 body. See gh-27052
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -156,7 +156,7 @@ public class DispatcherHandler implements WebHandler, PreFlightRequestHandler, A
|
||||
|
||||
private <R> Mono<R> createNotFoundError() {
|
||||
return Mono.defer(() -> {
|
||||
Exception ex = new ResponseStatusException(HttpStatus.NOT_FOUND, "No matching handler");
|
||||
Exception ex = new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
return Mono.error(ex);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -1261,8 +1261,7 @@ public abstract class RouterFunctions {
|
||||
}
|
||||
|
||||
private <R> Mono<R> createNotFoundError() {
|
||||
return Mono.defer(() -> Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND,
|
||||
"No matching router function")));
|
||||
return Mono.defer(() -> Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND)));
|
||||
}
|
||||
|
||||
private static <T> Mono<T> wrapException(Supplier<Mono<T>> supplier) {
|
||||
|
||||
@@ -200,8 +200,8 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
||||
|
||||
if (helper.hasParamsMismatch()) {
|
||||
throw new ServerWebInputException(
|
||||
"Unsatisfied query parameter conditions: " + helper.getParamConditions() +
|
||||
", actual parameters: " + request.getQueryParams());
|
||||
"Expected parameters: " + helper.getParamConditions() +
|
||||
", actual query parameters: " + request.getQueryParams());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -84,7 +84,7 @@ public class DispatcherHandlerErrorTests {
|
||||
StepVerifier.create(mono)
|
||||
.consumeErrorWith(ex -> {
|
||||
assertThat(ex).isInstanceOf(ResponseStatusException.class);
|
||||
assertThat(ex.getMessage()).isEqualTo("404 NOT_FOUND \"No matching handler\"");
|
||||
assertThat(ex.getMessage()).isEqualTo("404 NOT_FOUND");
|
||||
})
|
||||
.verify();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user