{"id":313166,"date":"2020-11-15T15:01:59","date_gmt":"2020-11-15T15:01:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=313166"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=313166","title":{"rendered":"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 Spring"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-r\/yw\/tl\/-rywtlq7bt1kzw9_nyrczahc1rg.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0427\u0430\u0441\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <strong>Spring Framework<\/strong> \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442!<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0434\u043e <strong>Spring 3.2<\/strong> \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0431\u044b\u043b\u0438 <em>HandlerExceptionResolver<\/em> \u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <em>@ExceptionHandler<\/em>. \u0418\u0445 \u043c\u044b \u0435\u0449\u0451 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043d\u0438\u0436\u0435, \u043d\u043e \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 3.2 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <em>@ControllerAdvice<\/em>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439. \u0410 \u0432 <strong>Spring 5<\/strong> \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <em>ResponseStatusException<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043b\u044f <strong>REST API<\/strong>.<\/p>\n<p>  <\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u043e \u0432\u0441\u0451\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443, \u043f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<p>  <\/p>\n<h3 id=\"obrabotka-isklyucheniy-na-urovne-kontrollera---exceptionhandler\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u2014 @ExceptionHandler<\/h3>\n<p>  <\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>@ExceptionHandler<\/em> \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0438 \u043f\u0440\u043e\u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e. <\/p>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class Example1Controller {      @GetMapping(value = &quot;\/testExceptionHandler&quot;, produces = APPLICATION_JSON_VALUE)     public Response testExceptionHandler(@RequestParam(required = false, defaultValue = &quot;false&quot;) boolean exception)             throws BusinessException {         if (exception) {             throw new BusinessException(&quot;BusinessException in testExceptionHandler&quot;);         }         return new Response(&quot;OK&quot;);     }      @ExceptionHandler(BusinessException.class)     public Response handleException(BusinessException e) {         return new Response(e.getMessage());     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u043c\u0435\u0442\u043e\u0434 <em>testExceptionHandler<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0435\u0440\u043d\u0451\u0442 \u043b\u0438\u0431\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <em>BusinessException<\/em>, \u043b\u0438\u0431\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u2014 \u0432\u0441\u0451 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0448\u0442\u0430\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439.<\/p>\n<p>  <\/p>\n<p>\u0410 \u0432\u043e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 <em>handleException <\/em>\u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0443\u0436\u0435 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a. \u0423 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <em>@ExceptionHandler(BusinessException.class)<\/em>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043d\u0430\u043c \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u044b \u0432\u0441\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <em>BusinessException<\/em>. \u0412 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>@ExceptionHandler<\/em> \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a: <em>@ExceptionHandler({BusinessException.class, ServiceException.class})<\/em>. <\/p>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u0430\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430 \u2014 \u043f\u043e \u0441\u0443\u0442\u0438 \u0432\u0435\u0440\u043d\u0451\u0442\u0441\u044f \u043a\u043e\u0434 200 \u0438 JSON \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0447\u0430\u0441\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <em>@ResponseStatus<\/em>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <em>@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)<\/em>.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nt\/kh\/1s\/ntkh1sjr5bk1gofumunw32xrp-0.png\"\/>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0448\u0442\u0430\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pe\/-2\/q2\/pe-2q2etjvd_johgdkh_x-w-0wu.png\"\/>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a <em>@ExceptionHandler<\/em> \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0430 \u043d\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u0435\u0441\u043b\u0438 <em>@ExceptionHandler<\/em> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0441\u0442\u0430\u0440\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043b\u0435\u0433\u0430\u0441\u0438. <\/p>\n<p>  <\/p>\n<h3 id=\"obrabotka-isklyucheniy-s-pomoschyu-handlerexceptionresolver\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e HandlerExceptionResolver<\/h3>\n<p>  <\/p>\n<p><strong>HandlerExceptionResolver <\/strong>\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0449\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 Spring. \u0412\u0441\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432\u044b\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432 <em>HandlerExceptionResolver<\/em>. \u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u0432\u043e\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u0442\u0430\u043a \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c Spring \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0438\u0445 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430:<\/p>\n<p>  <\/p>\n<p><strong>ExceptionHandlerExceptionResolver <\/strong> \u2014 \u044d\u0442\u043e\u0442 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>@ExceptionHandler<\/em>, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b \u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<p><strong>DefaultHandlerExceptionResolver <\/strong> \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 Spring \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>Exception<\/th>\n<th>HTTP Status Code<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>BindException<\/td>\n<td>400 (Bad Request)<\/td>\n<\/tr>\n<tr>\n<td>ConversionNotSupportedException<\/td>\n<td>500 (Internal Server Error)<\/td>\n<\/tr>\n<tr>\n<td>HttpMediaTypeNotAcceptableException<\/td>\n<td>406 (Not Acceptable)<\/td>\n<\/tr>\n<tr>\n<td>HttpMediaTypeNotSupportedException<\/td>\n<td>415 (Unsupported Media Type)<\/td>\n<\/tr>\n<tr>\n<td>HttpMessageNotReadableException<\/td>\n<td>400 (Bad Request)<\/td>\n<\/tr>\n<tr>\n<td>HttpMessageNotWritableException<\/td>\n<td>500 (Internal Server Error)<\/td>\n<\/tr>\n<tr>\n<td>HttpRequestMethodNotSupportedException<\/td>\n<td>405 (Method Not Allowed)<\/td>\n<\/tr>\n<tr>\n<td>MethodArgumentNotValidException<\/td>\n<td>400 (Bad Request)<\/td>\n<\/tr>\n<tr>\n<td>MissingServletRequestParameterException<\/td>\n<td>400 (Bad Request)<\/td>\n<\/tr>\n<tr>\n<td>MissingServletRequestPartException<\/td>\n<td>400 (Bad Request)<\/td>\n<\/tr>\n<tr>\n<td>NoSuchRequestHandlingMethodException<\/td>\n<td>404 (Not Found)<\/td>\n<\/tr>\n<tr>\n<td>TypeMismatchException<\/td>\n<td>400 (Bad Request)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430, \u0430 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0434\u043b\u044f REST API \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0447\u0430\u0441\u0442\u043e \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0416\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0435\u0449\u0435 \u0438 \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e. \u042d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>ModelAndView<\/em>, \u043d\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>  <\/p>\n<p><strong>ResponseStatusExceptionResolver <\/strong> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>@ResponseStatus<\/em>. <\/p>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <em>ServiceException<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) public class ServiceException extends Exception {      public ServiceException(String message) {         super(message);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 <em>ServiceException <\/em>\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>@ResponseStatus<\/em> \u0438 \u0432 <em>value<\/em> \u0443\u043a\u0430\u0437\u0430\u043b \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441\u0443 <em>INTERNAL_SERVER_ERROR<\/em>, \u0442\u043e \u0435\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0441\u0442\u0430\u0442\u0443\u0441-\u043a\u043e\u0434 500.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class Example2Controller {      @GetMapping(value = &quot;\/testResponseStatusExceptionResolver&quot;, produces = APPLICATION_JSON_VALUE)     public Response testResponseStatusExceptionResolver(@RequestParam(required = false, defaultValue = &quot;false&quot;) boolean exception)             throws ServiceException {         if (exception) {             throw new ServiceException(&quot;ServiceException in testResponseStatusExceptionResolver&quot;);         }         return new Response(&quot;OK&quot;);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c GET-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <em>exception=true<\/em>, \u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u0442\u0432\u0435\u0442 \u0432\u0435\u0440\u043d\u0451\u0442 500-\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ky\/c7\/se\/kyc7se_b3pm3cgaubk12sh0nz8y.png\"\/>  <\/p>\n<p>\u0418\u0437 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u2014 \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430. \u041d\u043e \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430, \u0442\u043e <em>@ResponseStatus<\/em> \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 HandlerExceptionResolver<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 JSON \u0438\u043b\u0438 XML \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439. \u041d\u043e \u043d\u0435 \u0441\u043f\u0435\u0448\u0438\u0442\u0435 \u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Component public class CustomExceptionResolver extends AbstractHandlerExceptionResolver {      @Override     protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {         ModelAndView modelAndView = new ModelAndView(new MappingJackson2JsonView());         if (ex instanceof CustomException) {             modelAndView.setStatus(HttpStatus.BAD_REQUEST);             modelAndView.addObject(&quot;message&quot;, &quot;CustomException was handled&quot;);             return modelAndView;          }         modelAndView.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);         modelAndView.addObject(&quot;message&quot;, &quot;Another exception was handled&quot;);         return modelAndView;     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443 \u0442\u0430\u043a \u0441\u0435\u0431\u0435, \u043f\u0440\u044f\u043c\u043e \u0441\u043a\u0430\u0436\u0435\u043c. \u041a\u043e\u0434 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0440\u0443\u043a\u0430\u043c\u0438: \u0441\u0430\u043c\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u0438\u043f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u0438 \u0441\u0430\u043c\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0440\u0435\u0432\u043d\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <em>ModelAndView<\/em>. \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 JSON, \u043d\u043e \u0432 \u043a\u043e\u0434\u0435 \u043a\u0440\u0430\u0441\u043e\u0442\u044b \u044f\u0432\u043d\u043e \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442. <\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0442\u0438\u043f\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0443\u0441-\u043a\u043e\u0434, \u0442\u0430\u043a \u0438 \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430. \u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043d \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u043c\u043d\u043e\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432. \u041d\u043e \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435. \u0410 \u0441\u0435\u0439\u0447\u0430\u0441, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u2014 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class Example3Controller {      @GetMapping(value = &quot;\/testCustomExceptionResolver&quot;, produces = APPLICATION_JSON_VALUE)     public Response testCustomExceptionResolver(@RequestParam(required = false, defaultValue = &quot;false&quot;) boolean exception)             throws CustomException {         if (exception) {             throw new CustomException(&quot;CustomException in testCustomExceptionResolver&quot;);         }         return new Response(&quot;OK&quot;);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0437\u043e\u0432\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0h\/2r\/v0\/0h2rv0n8kcbsqcoqjj_7w6_u5qg.png\"\/>  <\/p>\n<p>\u0412\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e\u0441\u044c \u0438 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043a\u043e\u0434 200 \u0438 JSON \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"obrabotka-isklyucheniy-s-pomoschyu-controlleradvice\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e @ControllerAdvice<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u2014 \u044d\u0434\u0432\u0430\u0439\u0441\u044b. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e <strong>Spring 3.2<\/strong> \u043c\u043e\u0436\u043d\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0438 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <em>@ControllerAdvice<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u0434\u0432\u0430\u0439\u0441\u0430 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@ControllerAdvice public class DefaultAdvice {      @ExceptionHandler(BusinessException.class)     public ResponseEntity&lt;Response&gt; handleException(BusinessException e) {         Response response = new Response(e.getMessage());         return new ResponseEntity&lt;&gt;(response, HttpStatus.OK);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u043b\u044e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <em>@ControllerAdvice<\/em> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f.<br \/>  \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 <em>DefaultAdvice<\/em> \u0441 \u043e\u0434\u043d\u0438\u043c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c <em>handleException<\/em>. \u041c\u0435\u0442\u043e\u0434 <em>handleException<\/em> \u0438\u043c\u0435\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>@ExceptionHandler<\/em>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439, \u043a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <em>BusinessException<\/em>. <\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0434\u043d\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441\u0440\u0430\u0437\u0443: <em>@ExceptionHandler({BusinessException.class, ServiceException.class})<\/em>. \u0422\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0434\u0432\u0430\u0439\u0441\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 <em>@ExceptionHandler<\/em> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439.<br \/>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <em>handleException<\/em> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <em>ResponseEntity<\/em> \u0441 \u043d\u0430\u0448\u0438\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c <em>Response<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class Response {      private String message;      public Response() {     }      public Response(String message) {         this.message = message;     }      public String getMessage() {         return message;     }      public void setMessage(String message) {         this.message = message;     }  } <\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043a\u0430\u043a \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430, \u0442\u0430\u043a \u0438 JSON \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0432 \u043f\u043e\u043b\u0435 message \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e <em>HttpStatus.OK<\/em>, \u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u0434\u0443 200.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0434\u0432\u0430\u0439\u0441\u0430 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class Example4Controller {      @GetMapping(value = &quot;\/testDefaultControllerAdvice&quot;, produces = APPLICATION_JSON_VALUE)     public Response testDefaultControllerAdvice(@RequestParam(required = false, defaultValue = &quot;false&quot;) boolean exception)             throws BusinessException {         if (exception) {             throw new BusinessException(&quot;BusinessException in testDefaultControllerAdvice&quot;);         }         return new Response(&quot;OK&quot;);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 JSON \u0438 \u043a\u043e\u0434 200: <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/t0\/im\/8_\/t0im8_hmkdi568jdnd9hfse0day.png\"\/>  <\/p>\n<p>\u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432?<br \/>  \u0422\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c! \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@ControllerAdvice(annotations = CustomExceptionHandler.class) public class CustomAdvice {      @ExceptionHandler(BusinessException.class)     public ResponseEntity&lt;Response&gt; handleException(BusinessException e) {         String message = String.format(&quot;%s %s&quot;, LocalDateTime.now(), e.getMessage());         Response response = new Response(message);         return new ResponseEntity&lt;&gt;(response, HttpStatus.OK);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>@ControllerAdvice(annotations = CustomExceptionHandler.class)<\/em>. \u0422\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0447\u0442\u043e <em>CustomAdvice<\/em> \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0442\u0435\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u044e\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>@CustomExceptionHandler<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>@CustomExceptionHandler<\/em> \u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u043b \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface CustomExceptionHandler { }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController @CustomExceptionHandler public class Example5Controller {      @GetMapping(value = &quot;\/testCustomControllerAdvice&quot;, produces = APPLICATION_JSON_VALUE)     public Response testCustomControllerAdvice(@RequestParam(required = false, defaultValue = &quot;false&quot;) boolean exception)             throws BusinessException {         if (exception) {             throw new BusinessException(&quot;BusinessException in testCustomControllerAdvice&quot;);         }         return new Response(&quot;OK&quot;);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 <em>Example5Controller<\/em> \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <em>@CustomExceptionHandler<\/em>, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e \u0436\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0447\u0442\u043e \u0438 \u0432 <em>Example4Controller <\/em>\u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <em>BusinessException <\/em>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e <em>CustomAdvice<\/em>, \u0430 \u043d\u0435 <em>DefaultAdvice<\/em>, \u0432 \u0447\u0451\u043c \u043c\u044b \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f. <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432 <em>CustomAdvice<\/em> \u2014 \u043d\u0430\u0447\u0430\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u0434\u0430\u0442\u0443:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/u6\/tx\/wx\/u6txwxrq9c7z-1pd-ddhpsvjkvi.png\"\/>  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u044d\u0434\u0432\u0430\u0439\u0441\u043e\u0432 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <em>@ControllerAdvice<\/em>, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u044d\u0434\u0432\u0430\u0439\u0441 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043f\u0430\u043a\u0435\u0442\u044b. \u041d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0432\u0435\u0448\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435. <\/p>\n<p>  <\/p>\n<h3 id=\"isklyuchenie-responsestatusexception\">\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 ResponseStatusException.<\/h3>\n<p>  <\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0451\u0442 \u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u0443\u0442\u0451\u043c \u0432\u044b\u0431\u0440\u043e\u0441\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <strong>ResponseStatusException<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@RestController public class Example6Controller {      @GetMapping(value = &quot;\/testResponseStatusException&quot;, produces = APPLICATION_JSON_VALUE)     public Response testResponseStatusException(@RequestParam(required = false, defaultValue = &quot;false&quot;) boolean exception) {         if (exception) {             throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, &quot;ResponseStatusException in testResponseStatusException&quot;);         }         return new Response(&quot;OK&quot;);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044f <em>ResponseStatusException<\/em> \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 \u043b\u043e\u0433\u0438\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <em>@ResponseStatus<\/em> \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u0441\u0442\u0430\u0442\u0443\u0441-\u043a\u043e\u0434. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0442\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0435\u043b\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043d\u043e \u0432 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u0435\u043d.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0437\u043e\u0432\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qm\/ac\/xs\/qmacxsuhsuqlctntkufvcheladq.png\"\/>  <\/p>\n<p><strong>\u0420\u0435\u0437\u044e\u043c\u0435<\/strong>: \u043c\u044b \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u044b\u043c \u0438 \u0441\u0442\u0430\u0440\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0435\u0440\u0435\u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a. \u0418\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0447\u0442\u043e \u043a\u0430\u043a\u043e\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0432 \u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043e\u0442\u0432\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0434\u0432\u0430\u0439\u0441\u043e\u0432, \u0442\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0441\u043b\u043e\u043c\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u0441\u0442\u0430\u0440\u044b\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432.<br \/>  \u0422\u0430\u043a \u0447\u0442\u043e \u0431\u0443\u0434\u044c\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u0438 \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e!<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/AlexeyKutepov\/exception-handler-example\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438<\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/528116\/\"> https:\/\/habr.com\/ru\/post\/528116\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-r\/yw\/tl\/-rywtlq7bt1kzw9_nyrczahc1rg.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0427\u0430\u0441\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <strong>Spring Framework<\/strong> \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-313166","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=313166"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313166\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}