40

SpringBoot 统一异常处理-wx5c9c81065cfc3的博客

 5 years ago
source link: https://blog.51cto.com/14262994/2375928
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
SpringBoot统一异常处理异常和响应码因为用RESTful设计的接口,应该用状态码反映请求的错误,不应该统一返回200的状态码,然后再通过msg来描述错误.所以统一异常处理比较关键.异常一般分为业务异常和非业务异常业务异常通常返回4xx的状态码非业务异常只需要返回500,提示服务器错误,请稍候重试默认异常处理SpringBoot提供了默认的处理异常方式,当出现异常时就会默认映射到/error

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK