Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop converting exceptions #175

Open
alalag1 opened this issue Apr 28, 2022 · 0 comments
Open

stop converting exceptions #175

alalag1 opened this issue Apr 28, 2022 · 0 comments
Assignees
Milestone

Comments

@alalag1
Copy link
Member

alalag1 commented Apr 28, 2022

Expected behavior

make a new abstraction for error handling

Actual behavior

protected WebApplicationException toJakartaException(RequestContext context, Throwable th) {
if (th instanceof WebApplicationException) {
return (WebApplicationException) th;
}
if (th instanceof WebServerException) {
WebServerException underlying = (WebServerException) th;
if (HttpStatus.BAD_REQUEST == underlying.status()) {
return new BadRequestException(th.getMessage(), extractCause(underlying));
}
if (HttpStatus.NOT_ACCEPTABLE == underlying.status()) {
return new NotAcceptableException(underlying.getMessage(), extractCause(underlying));
}
if (HttpStatus.UNSUPPORTED_MEDIA_TYPE == underlying.status()) {
return new NotAcceptableException(underlying.getMessage(), extractCause(underlying));
}
if (HttpStatus.NOT_FOUND == underlying.status()) {
RouteFailureException.RouteFailure routeFailure;
if ((routeFailure = context.attrs().attr(RoutePredicate.MISMATCH_ERR).get()) != null) {
switch (routeFailure) {
case METHOD_MISMATCH:
return new NotAllowedException(Response.status(HttpStatus.METHOD_NOT_ALLOWED
.code()).build());
case CONSUMES_MISMATCH:
return new NotSupportedException(underlying.getMessage(), extractCause(underlying));
case PRODUCES_MISMATCH:
return new NotAcceptableException(underlying.getMessage(), extractCause(underlying));
case PATTERN_MISMATCH:
case HEADER_MISMATCH:
return new BadRequestException(underlying.getMessage(), extractCause(underlying));
default:
return new NotFoundException(underlying.getMessage(), extractCause(underlying));
}
}
return new NotFoundException(underlying.getMessage(), extractCause(underlying));
}
if (HttpStatus.INTERNAL_SERVER_ERROR == underlying.status()) {
return new InternalServerErrorException(underlying.getMessage(), extractCause(underlying));
}
}
return new InternalServerErrorException(th.getMessage(), th);
}

this would hurt performance

Steps to reproduce

Env

  • Restlight version: 1.0.0-SNAPSHOT
@LCDZhao-Z LCDZhao-Z self-assigned this May 6, 2022
@LCDZhao-Z LCDZhao-Z added this to the v1.0.1 milestone May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants