Handling ResponseStatusException Results in 502

未關閉
#342 8 則留言 2 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@sapessi 已經在處理了。

開始於 2020年7月10日。

評估

這個 Issue 還沒有評估資料。

描述

need feedback
  • Framework version: 1.5 / 5.2.6-RELEASE
  • Implementations: Spring

Scenario

I am throwing a ResponseStatusException to handle 404's, 500's, etc but no matter when I throw one I am getting the following response with a 502 from the call:

{
    "message": "Gateway timeout"
}

This is an example of how I am creating the ResponseStatusException:

            if(queryResults.getSize() == 0) {
                throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Unable To Find User for Email Address %s", email));
            } else {
              // Do something else
            }

I am seeing the following in my logs so I know the exception is being thrown properly:

2020-05-04 21:20:04 f1ab9c4e-75ee-457f-b222-dedc69daf8f5 ERROR LambdaContainerHandler - Error while handling request
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.server.ResponseStatusException: 404 NOT_FOUND "Unable To Find User for Email Address [email protected]"

It doesn't seem to handle the ResponseStatusException being thrown. I added the following to my application config class:

    /*
     * optimization - avoids creating default exception resolvers; not required as the serverless container handles
     * all exceptions
     *
     * By default, an ExceptionHandlerExceptionResolver is created which creates many dependent object, including
     * an expensive ObjectMapper instance.
     *
     * To enable custom @ControllerAdvice classes remove this bean.
     */
    @Bean
    public HandlerExceptionResolver handlerExceptionResolver() {
        return new HandlerExceptionResolver() {

            @Override
            public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
                return null;
            }
        };
    }

Shouldn't the container handle the ResponseStatusException automatically?

Thanks,
Steve

Expected behavior

The proper response code and response returned

Actual behavior

Always retuning a 502 and Bad Gateway reponse

主要語言
Java
星號
1.6k
分支
575
平均合併
1 天 15 小時
30 天內合併 PR
12

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws/serverless-java-container 的其他 Issue

查看 aws/serverless-java-container 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。