How to Utilize AI and Programming for Value Investing with Python

Programming and AI can be used in value investing but not in typical ways as you think. Artificial intelligence and programming makes value investing easier to do.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Exception Handling for REST API with Spring Boot

Exception handling is very important and must have feature for RESTful APIs.

A good error messages help clients to take corrective actions to handle the critical situations in the applications.In this post, we are going to implement exception handling with spring boot latest release.

Why Spring Boot,

Spring boot provides the out of the box white label error handling feature.For example if you run sample default spring boot application you can see default error page for invalid endpoint like this.

We are going to customize the default spring boot error message with new meaningful JSON error message. For example,

In this error JSON we define attributes in following way.
* The status represents HTTP status code.
* The path field specifies a link for detail information about the error or exception.
* The errorMessage field represents human-readable error message.
* The timeStamp field represents error occurred time.
* The trace section represents error information with complete details which is important for developers.

Spring and Spring Boot provides a number of options for error/exception handling.

1) ExceptionHandler Annotation

This annotation works at the @Controller class level.The issue with the approach is only active for the given controller.The annotation is not global, so we need to implement in each and every controller.

2) @ControllerAdvice Annotation

This annotation supports global Exception handler mechanism.So we can implement the controller exception handling events in a central location.

3) ResponseEntityExceptionHandler

This method can be used with @ControllerAdvice classes.It allows the developer to specify some specific templates of ResponseEntity and return values.

4) @RestControllerAdvice

Spring Boot 1.4 introduced the @RestControllerAdvice annotation for easier exception handling.It is a convenience annotation that is itself annotated with @ControllerAdvice and @ResponseBody.

5) In spring boot implementing the ErrorController and overriding the default whitelabel error template.

In our case Spring Boot by default error page is map with /error URI to BasicErrorController which populates model with error attributes and then returns ‘error’ as the view name to map application defined error pages.

When we override the default error template we have the define the server.error.whitelabel.enabled=false in the spring boot project application.properties file.

Total sample project is avalible in my github repository.Feel free to clone and modify repo as you want.

References :

Add a comment

Related posts:

Quick fix or long term?

If you thought that 2018 represented the peak of your compliance efforts, think again; prepare for a whole raft of new privacy laws coming into effect in 2019 and 2020. The most noteworthy ones will…

10 Sensational Ideas To Create A Unique Bedding Set Sport Collection Today.

Remind yourself of your favorite NFL team with this incredible Buffalo Bills Logo Sport Bedding Set. These luxurious bed linens feature the official rich blue and red logo of the Buffalo Bills, sure…

Broken LCD Screen Phone

Are you dealing with the frustration of a broken LCD screen phone? Look no further than Real Mobile Repair for top-notch repair services. Real Mobile Repair’s skilled technicians are here to fix your…