zowe / sample-spring-boot-api-service

Zowe REST API service SDK and sample API service that integrates with Zowe API Mediation Layer
Other
26 stars 18 forks source link

Uncaught Exception Example #52

Closed dkelosky closed 4 years ago

dkelosky commented 4 years ago

The API doc states: "Unexpected errors does not need to be handled or caught by your REST controller. If your controller throws an Exception or RuntimeException then Spring exception handler (customized by CustomRestExceptionHandler in the commons library) will convert the exception into a standardized format. "

Is information available on what content is produced by the commons package for an uncaught exception? For example, does it produce a stack trace, or other detailed information?

Reported by @gejohnston

dkelosky commented 4 years ago

Trying this out, I added a line to the GreetingController: throw new Exception("I'm a failure");

In the log I get the stack trace:

java.lang.Exception: I'm a failure
        at org.zowe.sample.apiservice.greeting.GreetingController.greeting(GreetingController.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
...

I get this API response from this:

{"messages":[{"messageKey":"org.zowe.commons.rest.internalServerError","messageType":"ERROR","messageNumber":"ZWEAS500","messageContent":"The service has encountered a situation it doesn't know how to handle. Please contact support for further assistance. More details are available in the log under the provided message instance ID","messageInstanceId":"9dea2819-1d5f-439e-8020-fb44888f44ae"}]}

Does this capture what you were asking?

dkelosky commented 4 years ago

BTW, the sample also has an endpoint for throwing a RuntimeException already without code changes via /api/v1/greeting/failed with the same behavior as above.

gejohnston commented 4 years ago

With this information, we know what output (and log details) a customer will see if an exception is not handled. Thanks.

dkelosky commented 4 years ago

Thank you