1
votes

I am setting up new microservice api to connect and grab information from 3rd party REST api. This is the api more like internal for our services so other api's can consume this one.

I have an internal microservice design like this:

Controller -> (calls) -> Service Layer -> (calls) -> Service Implementation -> (calls) -> rest 3rd party API

Error Handling as below, when there is any issue/exception i fill all ErrorDetailsObj in exception handler(@ControllerAdvice) and return the response entity wrapper to the consuming services.

public class ErrorObject {
    private String code;
    private String message; //(i choose message from error.prop based on the code)
}


public class ErrorDetailsObj {
    private HttpStatus httpStatus;
    private LocalDateTime timestamp;
    private String message;
    private List<ErrorObject> errors;
}
  1. Am I doing the right design? Or is there any better way to simplify the error handling?
  2. Do I need to send only error code, so that consuming services can choose the right error message and display? in my case this is my own internal service which connects to 3rd party service.
  3. Any best example's for error handling?
2
Does it work? What would "better" mean?jonrsharpe
yah it works, but i need to know any other better designs than this, possibly expose only error code so that consuming services can make use of error messages in there services. but drawback is that all consuming services has to expose error messages to be placed in there services... so need a better design or approachSatscreate
Wouldn't codereview SE be a better place to ask this question ?Marged

2 Answers

0
votes

I am not sure, but u should send correct http code and your message. Also u can look at default spring exception handler ResponseEntityExceptionHandler.

0
votes

I don't see any issue with your approach. and since you mentioned that it's working fine, you would have already defined all the required classes custom exceptions classes. and per your question: 'possibly expose only error code so that consuming services can make use of error messages in there services'. - you need to fill the error message where you are seeing the exception (source).

I can suggest one small change, you can extract httpStatus out of ErrorDetailsObj. while returning the ResponseEntity object, you can HttpStatus to the cconstructor of ResponseEntity. ex: return ResponseEntity(errorDetailsObj, HttpStatus.<>);

Hope this helps.