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

Exception Handling in the Service Implementations is unflexible #20

Open
a-marcel opened this issue Feb 9, 2017 · 0 comments
Open

Exception Handling in the Service Implementations is unflexible #20

a-marcel opened this issue Feb 9, 2017 · 0 comments

Comments

@a-marcel
Copy link

a-marcel commented Feb 9, 2017

Hi,

the idea with the Rest API Class and the Service Impl is very good and i like it. My Problem is, that if an Impl. throws an exception, it results all the time in a HTTP Error 500.

From my point of view, there should be some default Exceptions.

An idea is to create a BaseException and some Special Exception (extends the BaseException) and containing the http error code.

Inside the Service Impl i can throw this special Exception and the function internalError handle this and change the HTTP Status.

protected void internalError(RoutingContext context, Throwable ex) {
		context.response().setStatusCode(500).putHeader(HttpHeaders.CONTENT_TYPE.toString(), "application/json");
		
		if (ex instanceof CustomBaseException) {
			context.response().setStatusCode(((CustomBaseException)ex).getHttpStatusCode());
		}
		
		context.response().end(new JsonObject().put("error", ex.getMessage()).encodePrettily());
	}

Or do you've an other concept to control the HTTP Status codes inside the Service Implementations ?

Thanks
Marcel

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

1 participant