how to handle errors happening on the backend with zuul?











up vote
0
down vote

favorite












I have the scenario presented here. However, I configured the backend side (the one that receives the file and saves it) to accept files with a maximum size of 10 MB.



My problem is that I don't know how to handle the error that occurs when I send files larger than 10 MB.



Here's the error that I get in the frontend:



2018-11-19 16:20:51.317  INFO 4868 --- [o-10082-exec-10] o.apache.http.impl.execchain.RetryExec   : I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:9082: Software caused connection abort: socket write error
2018-11-19 16:20:51.317 WARN 4868 --- [o-10082-exec-10] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering

com.netflix.zuul.exception.ZuulException: null
at org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException.<init>(ZuulRuntimeException.java:33) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.run(SimpleHostRoutingFilter.java:207) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.3.0.jar:1.3.0]
at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) ~[zuul-core-1.3.0.jar:1.3.0]
[...]
Caused by: org.apache.http.client.ClientProtocolException: null
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.3.jar:4.5.3]
at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forwardRequest(SimpleHostRoutingFilter.java:332) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forward(SimpleHostRoutingFilter.java:251) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
[...]
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:108) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.3.jar:4.5.3]
[...]
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_92]
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) ~[na:1.8.0_92]
at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.8.0_92]
at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124) ~[httpcore-4.4.6.jar:4.4.6]
[...]


The backend error is handled fine, here's how it looks like:



16:20:39.764 WARN  [http-nio-9082-exec-1] o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolved exception caused by Handler execution: org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 20971520 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 20971520 bytes.


Any idea how I should handle the backend error ?



Of course, I will validate the file size on the Frontend as well, but I need to be able to handle that exception gracefully.



Thanks in advance !










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have the scenario presented here. However, I configured the backend side (the one that receives the file and saves it) to accept files with a maximum size of 10 MB.



    My problem is that I don't know how to handle the error that occurs when I send files larger than 10 MB.



    Here's the error that I get in the frontend:



    2018-11-19 16:20:51.317  INFO 4868 --- [o-10082-exec-10] o.apache.http.impl.execchain.RetryExec   : I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:9082: Software caused connection abort: socket write error
    2018-11-19 16:20:51.317 WARN 4868 --- [o-10082-exec-10] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering

    com.netflix.zuul.exception.ZuulException: null
    at org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException.<init>(ZuulRuntimeException.java:33) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.run(SimpleHostRoutingFilter.java:207) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
    at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.3.0.jar:1.3.0]
    at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) ~[zuul-core-1.3.0.jar:1.3.0]
    [...]
    Caused by: org.apache.http.client.ClientProtocolException: null
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.3.jar:4.5.3]
    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forwardRequest(SimpleHostRoutingFilter.java:332) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forward(SimpleHostRoutingFilter.java:251) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
    [...]
    Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:108) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.3.jar:4.5.3]
    [...]
    Caused by: java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_92]
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) ~[na:1.8.0_92]
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.8.0_92]
    at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124) ~[httpcore-4.4.6.jar:4.4.6]
    [...]


    The backend error is handled fine, here's how it looks like:



    16:20:39.764 WARN  [http-nio-9082-exec-1] o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolved exception caused by Handler execution: org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 20971520 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 20971520 bytes.


    Any idea how I should handle the backend error ?



    Of course, I will validate the file size on the Frontend as well, but I need to be able to handle that exception gracefully.



    Thanks in advance !










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have the scenario presented here. However, I configured the backend side (the one that receives the file and saves it) to accept files with a maximum size of 10 MB.



      My problem is that I don't know how to handle the error that occurs when I send files larger than 10 MB.



      Here's the error that I get in the frontend:



      2018-11-19 16:20:51.317  INFO 4868 --- [o-10082-exec-10] o.apache.http.impl.execchain.RetryExec   : I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:9082: Software caused connection abort: socket write error
      2018-11-19 16:20:51.317 WARN 4868 --- [o-10082-exec-10] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering

      com.netflix.zuul.exception.ZuulException: null
      at org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException.<init>(ZuulRuntimeException.java:33) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.run(SimpleHostRoutingFilter.java:207) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.3.0.jar:1.3.0]
      at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) ~[zuul-core-1.3.0.jar:1.3.0]
      [...]
      Caused by: org.apache.http.client.ClientProtocolException: null
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187) ~[httpclient-4.5.3.jar:4.5.3]
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.3.jar:4.5.3]
      at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forwardRequest(SimpleHostRoutingFilter.java:332) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forward(SimpleHostRoutingFilter.java:251) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      [...]
      Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:108) ~[httpclient-4.5.3.jar:4.5.3]
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.3.jar:4.5.3]
      [...]
      Caused by: java.net.SocketException: Software caused connection abort: socket write error
      at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_92]
      at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) ~[na:1.8.0_92]
      at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.8.0_92]
      at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124) ~[httpcore-4.4.6.jar:4.4.6]
      [...]


      The backend error is handled fine, here's how it looks like:



      16:20:39.764 WARN  [http-nio-9082-exec-1] o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolved exception caused by Handler execution: org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 20971520 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 20971520 bytes.


      Any idea how I should handle the backend error ?



      Of course, I will validate the file size on the Frontend as well, but I need to be able to handle that exception gracefully.



      Thanks in advance !










      share|improve this question













      I have the scenario presented here. However, I configured the backend side (the one that receives the file and saves it) to accept files with a maximum size of 10 MB.



      My problem is that I don't know how to handle the error that occurs when I send files larger than 10 MB.



      Here's the error that I get in the frontend:



      2018-11-19 16:20:51.317  INFO 4868 --- [o-10082-exec-10] o.apache.http.impl.execchain.RetryExec   : I/O exception (java.net.SocketException) caught when processing request to {}->http://localhost:9082: Software caused connection abort: socket write error
      2018-11-19 16:20:51.317 WARN 4868 --- [o-10082-exec-10] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering

      com.netflix.zuul.exception.ZuulException: null
      at org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException.<init>(ZuulRuntimeException.java:33) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.run(SimpleHostRoutingFilter.java:207) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.3.0.jar:1.3.0]
      at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) ~[zuul-core-1.3.0.jar:1.3.0]
      [...]
      Caused by: org.apache.http.client.ClientProtocolException: null
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187) ~[httpclient-4.5.3.jar:4.5.3]
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.3.jar:4.5.3]
      at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forwardRequest(SimpleHostRoutingFilter.java:332) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      at org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.forward(SimpleHostRoutingFilter.java:251) ~[spring-cloud-netflix-core-1.4.4.RELEASE.jar:1.4.4.RELEASE]
      [...]
      Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:108) ~[httpclient-4.5.3.jar:4.5.3]
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.3.jar:4.5.3]
      [...]
      Caused by: java.net.SocketException: Software caused connection abort: socket write error
      at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_92]
      at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) ~[na:1.8.0_92]
      at java.net.SocketOutputStream.write(SocketOutputStream.java:153) ~[na:1.8.0_92]
      at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124) ~[httpcore-4.4.6.jar:4.4.6]
      [...]


      The backend error is handled fine, here's how it looks like:



      16:20:39.764 WARN  [http-nio-9082-exec-1] o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolved exception caused by Handler execution: org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 20971520 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 20971520 bytes.


      Any idea how I should handle the backend error ?



      Of course, I will validate the file size on the Frontend as well, but I need to be able to handle that exception gracefully.



      Thanks in advance !







      spring-boot error-handling netflix-zuul






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 12:46









      Ionut

      334




      334
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You can create a custom error handler based on your exceptions that you need to handle.



          @ControllerAdvice
          public class EntityExceptionHandler
          extends ResponseEntityExceptionHandler {

          @ExceptionHandler(value = { ClientProtocolException.class })
          protected ResponseEntity<Object> handleClientProtocol(ClientProtocolException ex, WebRequest request) {
          return handleExceptionInternal(ex, "Here you need to put the error message",
          new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
          }
          }


          You can see ways to handle exceptions here error handlers






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393303%2fhow-to-handle-errors-happening-on-the-backend-with-zuul%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            You can create a custom error handler based on your exceptions that you need to handle.



            @ControllerAdvice
            public class EntityExceptionHandler
            extends ResponseEntityExceptionHandler {

            @ExceptionHandler(value = { ClientProtocolException.class })
            protected ResponseEntity<Object> handleClientProtocol(ClientProtocolException ex, WebRequest request) {
            return handleExceptionInternal(ex, "Here you need to put the error message",
            new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
            }
            }


            You can see ways to handle exceptions here error handlers






            share|improve this answer

























              up vote
              0
              down vote













              You can create a custom error handler based on your exceptions that you need to handle.



              @ControllerAdvice
              public class EntityExceptionHandler
              extends ResponseEntityExceptionHandler {

              @ExceptionHandler(value = { ClientProtocolException.class })
              protected ResponseEntity<Object> handleClientProtocol(ClientProtocolException ex, WebRequest request) {
              return handleExceptionInternal(ex, "Here you need to put the error message",
              new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
              }
              }


              You can see ways to handle exceptions here error handlers






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                You can create a custom error handler based on your exceptions that you need to handle.



                @ControllerAdvice
                public class EntityExceptionHandler
                extends ResponseEntityExceptionHandler {

                @ExceptionHandler(value = { ClientProtocolException.class })
                protected ResponseEntity<Object> handleClientProtocol(ClientProtocolException ex, WebRequest request) {
                return handleExceptionInternal(ex, "Here you need to put the error message",
                new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
                }
                }


                You can see ways to handle exceptions here error handlers






                share|improve this answer












                You can create a custom error handler based on your exceptions that you need to handle.



                @ControllerAdvice
                public class EntityExceptionHandler
                extends ResponseEntityExceptionHandler {

                @ExceptionHandler(value = { ClientProtocolException.class })
                protected ResponseEntity<Object> handleClientProtocol(ClientProtocolException ex, WebRequest request) {
                return handleExceptionInternal(ex, "Here you need to put the error message",
                new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
                }
                }


                You can see ways to handle exceptions here error handlers







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 13:24









                Jonathan Johx

                620111




                620111






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393303%2fhow-to-handle-errors-happening-on-the-backend-with-zuul%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen