Feature Request P2
Status Update
Comments
io...@google.com <io...@google.com>
ja...@gmail.com <ja...@gmail.com> #2
I have forwarded this request to the engineering team. We will update this issue with any progress updates and a resolution.
Best Regards,
Josh Moyer
Google Cloud Platform Support
Best Regards,
Josh Moyer
Google Cloud Platform Support
ja...@gmail.com <ja...@gmail.com> #3
This is not only useful for IP addresses, but also for many other resources. I understand that names are currently used as identifiers, so this request is probably not trivial to implement. Maybe distinguishing between a (numeric, automatically generated) identifier and a (textual) label is the way to go?
Description
A new annotation would be great that is similar to @ApiTransformer. Let's call it @ExceptionTransformer for now.
While @ApiTransformer defines transformations in both directions, the @ExceptionTransformer would define only one direction: how to transform an exception to a return value.
The @ExceptionTransformer annotation should be used to annotate exception classes.
Every time an exception is thrown from an API method that has an associated @ExceptionTransformer annotation then instead of the current exception handling mechanism of Cloud Endpoints, the new object (the result of the transformer) should be returned as a return value (as a JSON body, as usual with entity return types).
* Why are current approaches or workarounds insufficient?
Right now, if an exception is thrown then it results in an HTTP 4xx or HTTP 5xx response with a quite predefined JSON body.
If I throw a subclass of com.google.api.server.spi.ServiceException and set statusCode to 200 and add extra properties (getters), the JSON body in the response will (still) contain only the 'error_message' field.
Currently, I can return custom, app specific error message (JSON) bodies with custom java return types but in this case I would lose the power of the exception mechanism, i.e. I would need to pass along return values to communicate error situations (yuck).
* What new use cases will this feature will enable?
There are cases when I'd like to communicate errors not on the HTTP level (i.e. not with HTTP status codes). I'd like to return custom JSON (error) messages with an app specific structure in the response body that are triggered by exceptions in my java code.