aziz
(Abdul Aziz Murad)
August 17, 2021, 4:03am
#1
Hello,
How do we handle exceptions during API calls.
e.g. currently APIs always return 200 as long as the API call is valid.
We would like to return BAD REQUEST if there was any issues with parameters or throw custom exception with error message to frontend
I can use ReposneEntity with no issues if it was used custom controller in Portal module but when its used in Core module I get Serialization Error
albudarov
(Alexander Budarov)
August 25, 2021, 9:30am
#2
Hi,
Handling the exception is possible, you need to create a Spring MVC exception handler.
Examples were presented on the forum earlier:
Hi.
Information about the the first issue :
We found that the custom exception declared in the wrong package. Exception classes should be declared in the global module.
https://doc.cuba-platform.com/manual-latest/exception_classes.html
Information about the second issue :
If you want to see the useful detailed message for the custom exception you need to create a handler for the exception. For system exceptions, we don’t provide a detailed message about the server error.
You can create an ex…
You can do the following.
Instead of the HttpClientErrorException throw your own custom exception:
@SupportedByClient
public class MyRestException extends RuntimeException {
private HttpStatus httpStatus;
public MyRestException(String message, HttpStatus httpStatus) {
super(message);
this.httpStatus = httpStatus;
}
public HttpStatus getHttpStatus() {
return httpStatus;
}
}
Place the exception to the global module. Note that the exception has the @…