Coder Social home page Coder Social logo

mechero / spring-boot-rest-exceptions Goto Github PK

View Code? Open in Web Editor NEW
95.0 2.0 28.0 337 KB

Custom error formatting and exception handling in Rest Controllers with Spring Boot

Home Page: https://thepracticaldeveloper.com/2019/09/09/custom-error-handling-rest-controllers-spring-boot/

Java 100.00%
spring-boot rest-api error-handling exception-handler controller-advice java java12

spring-boot-rest-exceptions's Introduction

Handling errors in REST Controllers with Spring Boot

Goal

This sample code shows how configure a Spring Boot application to properly handle all exceptions and create your custom error format.

Check the blog post on ThePracticalDeveloper site for the complete guide with instructions.

Custom Error Handling in Spring Boot REST Controllers

And, if you find this code useful, please give a star to the repo!

Custom error handling

First, you'll find in this code an example of a basic approach to map exceptions to status codes in Spring Boot using a @RestControllerAdvice with @ExceptionHandler methods.

However, the most interesting part is the injection of a customized ErrorController implementation and the overridden ErrorAttributes to achieve consistent responses when dealing with errors.

For this example, I used the Google JSON Style Guide but you can use any other known error formatting or create your own one.

Check the guide for more details.

spring-boot-rest-exceptions's People

Contributors

mechero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.