Skip to content

Commit

Permalink
Merge pull request #20018 from geoand/rr-error-message
Browse files Browse the repository at this point in the history
Add specific information when throwing spec mandated exceptions
  • Loading branch information
geoand authored Sep 9, 2021
2 parents 4af8f36 + cdbf878 commit b0d086a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler;

public class ClassRoutingHandler implements ServerRestHandler {
private static final String INVALID_ACCEPT_HEADER_MESSAGE = "The accept header value did not match the value in @Produces";

private final Map<String, RequestMapper<RuntimeResource>> mappers;
private final int parameterOffset;

Expand Down Expand Up @@ -110,7 +112,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
if (MediaTypeHelper.getFirstMatch(
target.value.getConsumes(),
Collections.singletonList(MediaType.valueOf(contentType))) == null) {
throw new NotSupportedException();
throw new NotSupportedException("The content-type header value did not match the value in @Consumes");
}
}
}
Expand All @@ -126,7 +128,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
MediaType acceptsMediaType = MediaType.valueOf(accepts.trim());
MediaType providedMediaType = producesMediaTypes[0];
if (!providedMediaType.isCompatible(acceptsMediaType)) {
throw new NotAcceptableException();
throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE);
}
} else if (multipleAcceptsValues && (producesMediaTypes.length == 1)) {
// this is fairly common case, so we want it to be as fast as possible
Expand Down Expand Up @@ -156,7 +158,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
} while (true);

if (!compatible) {
throw new NotAcceptableException();
throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE);
}
} else {
// don't use any of the JAX-RS stuff from the various MediaType helper as we want to be as performant as possible
Expand All @@ -173,7 +175,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
}
if (MediaTypeHelper.getFirstMatch(Arrays.asList(producesMediaTypes),
acceptsMediaTypes) == null) {
throw new NotAcceptableException();
throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE);
}
}
}
Expand All @@ -197,7 +199,7 @@ private MediaType toMediaType(String mediaTypeStr) {
private void throwNotFound(ResteasyReactiveRequestContext requestContext) {
// the exception mapper needs access to request scoped beans, so make sure we have the context
requestContext.requireCDIRequestScope();
throw new NotFoundException();
throw new NotFoundException("Unable to find matching target resource method");
}

private String getRemaining(ResteasyReactiveRequestContext requestContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
return;
}
}
throw new NotSupportedException();
throw new NotSupportedException("No supported MessageBodyReader found");
}

private boolean isReadable(MessageBodyReader<?> reader, ResteasyReactiveRequestContext requestContext,
Expand Down

0 comments on commit b0d086a

Please sign in to comment.