vert-x3 / issues

Apache License 2.0
37 stars 7 forks source link

Improvements For Web API Services #584

Open InfoSec812 opened 3 years ago

InfoSec812 commented 3 years ago

Describe the feature

Modify the Web API Service code generators to support responses with custom exceptions. Right now, in an implementation of the service interface, if I call the provided handler with a custom exception the information in the message is never surfaced.

Example:

@Override
public void gettodos(ServiceRequest context, Handler<AsyncResult<ServiceResponse>> resultHandler) {
    resultHandler.handle(Future.failedFuture(new NotImplementedException("Not yet implemented: gettodos")));
}

The resulting REST response created by ErrorHandler does not retain that custom error message. It appears to get swallowed by ServiceException and instead the resulting error just says:

{"error":{"code":500,"message":"Internal Server Error"}}

In my mind, it would make sense to somehow be able to create a failed request where the status code and error message could be specified in the implementation method.

Use cases

This would make it easier to integrate with OpenAPI Generator so that I can generate stubs which have this sort of placeholder implementation

Contribution

I am willing to look at it myself, but would need some assistance in getting familiar with the relevant components.

pmlopes commented 3 years ago

@InfoSec812 this is definitely something we should improve. Currently, we started to use HttpException as the “default” exception type in vert.x web to signal exceptions with an associated HTTP status code. It seems we didn't consider the full stack.

If we could make these 2 exceptions, a hierarchy, then we could solve the problem by itself.

Given that service exception lives in vertx-service-proxy and http exception in vertx-web we may need to propose moving http exception to vertx-web-common and make service exception extend it? (this would avoid having a larger dependency tree pulled for service proxies).

Ideally, I guess if we could move HttpException to vertx-core would be even cleaner, as it would avoid touching dependencies at all.

/cc @vietj

vietj commented 3 years ago

is there a way to have service-proxy ship directly the code using ServiceException ?

vietj commented 3 years ago

it looks like a bug to me do you have a simple reproducer ?

InfoSec812 commented 3 years ago

@vietj Yes, here is a reduced and simplified reproducer.