Yi EungJun 2015-04-01
Show appropriate message when database timeout occurs
@9310254ad36234b47afa68a0d9a4fdbba8fd7795
app/Global.java
--- app/Global.java
+++ app/Global.java
@@ -45,6 +45,7 @@
 import views.html.welcome.secret;
 
 import javax.annotation.Nonnull;
+import javax.persistence.PersistenceException;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -303,7 +304,13 @@
         AccessLogger.log(request, null, Http.Status.INTERNAL_SERVER_ERROR);
 
         if (Play.isProd()) {
-            return Promise.pure((Result) Results.internalServerError(views.html.error.internalServerError_default.render("error.internalServerError")));
+            String messageKey;
+            if (t.getCause() instanceof PersistenceException && StringUtils.contains(t.getMessage(), "timed out")){
+                messageKey = "error.timeout";
+            } else {
+                messageKey = "error.internalServerError";
+            }
+            return Promise.pure((Result) Results.internalServerError(views.html.error.internalServerError_default.render(messageKey)));
         } else {
             return super.onError(request, t);
         }
conf/messages
--- conf/messages
+++ conf/messages
@@ -193,6 +193,7 @@
 error.failedTo = Failed to {0}<br>({1} {2})
 error.forbidden = You are not authorized
 error.forbidden.or.notfound = Project not exists or unauthorized user
+error.timeout = Your request could not be processed because of server timeout
 error.internalServerError = Server error has occurred; service is not available
 error.notfound = Page not found
 error.notfound.board_post = Post not exists
conf/messages.ko-KR
--- conf/messages.ko-KR
+++ conf/messages.ko-KR
@@ -193,6 +193,7 @@
 error.failedTo = {0}에 실패했습니다.<br>({1} {2})
 error.forbidden = 권한이 없습니다
 error.forbidden.or.notfound = 권한이 없거나 존재하지 않는 프로젝트입니다.
+error.timeout = 요청 처리가 너무 오래 걸려 중단되었습니다
 error.internalServerError = 서버 오류가 발생하여 서비스를 이용할 수 없습니다
 error.notfound = 페이지를 찾을 수 없습니다
 error.notfound.board_post = 존재하지 않는 글입니다
Add a comment
List