mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 00:01:51 -05:00
✨ Properly handle 'idle-in-tx' errors.
This commit is contained in:
parent
7b4ca6dcef
commit
993530dbcb
1 changed files with 47 additions and 7 deletions
|
@ -10,6 +10,7 @@
|
||||||
(ns app.http.errors
|
(ns app.http.errors
|
||||||
"A errors handling for the http server."
|
"A errors handling for the http server."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.util.log4j :refer [update-thread-context!]]
|
[app.util.log4j :refer [update-thread-context!]]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
|
@ -86,6 +87,15 @@
|
||||||
|
|
||||||
(defmethod handle-exception :default
|
(defmethod handle-exception :default
|
||||||
[error request]
|
[error request]
|
||||||
|
(let [edata (ex-data error)]
|
||||||
|
;; NOTE: this is a special case for the idle-in-transaction error;
|
||||||
|
;; when it happens, the connection is automatically closed and
|
||||||
|
;; next-jdbc combines the two errors in a single ex-info. We only
|
||||||
|
;; need the :handling error, because the :rollback error will be
|
||||||
|
;; always "connection closed".
|
||||||
|
(if (and (ex/exception? (:rollback edata))
|
||||||
|
(ex/exception? (:handling edata)))
|
||||||
|
(handle-exception (:handling edata) request)
|
||||||
(let [cdata (get-error-context request error)]
|
(let [cdata (get-error-context request error)]
|
||||||
(update-thread-context! cdata)
|
(update-thread-context! cdata)
|
||||||
(log/errorf error "internal error: %s (id: %s)"
|
(log/errorf error "internal error: %s (id: %s)"
|
||||||
|
@ -94,7 +104,37 @@
|
||||||
{:status 500
|
{:status 500
|
||||||
:body {:type :server-error
|
:body {:type :server-error
|
||||||
:hint (ex-message error)
|
:hint (ex-message error)
|
||||||
:data (ex-data error)}}))
|
:data edata}}))))
|
||||||
|
|
||||||
|
(defmethod handle-exception org.postgresql.util.PSQLException
|
||||||
|
[error request]
|
||||||
|
(let [cdata (get-error-context request error)
|
||||||
|
state (.getSQLState ^java.sql.SQLException error)]
|
||||||
|
|
||||||
|
(update-thread-context! cdata)
|
||||||
|
(log/errorf error "PSQL Exception: %s (id: %s, state: %s)"
|
||||||
|
(ex-message error)
|
||||||
|
(str (:id cdata))
|
||||||
|
state)
|
||||||
|
|
||||||
|
(cond
|
||||||
|
(= state "57014")
|
||||||
|
{:status 504
|
||||||
|
:body {:type :server-timeout
|
||||||
|
:code :statement-timeout
|
||||||
|
:hint (ex-message error)}}
|
||||||
|
|
||||||
|
(= state "25P03")
|
||||||
|
{:status 504
|
||||||
|
:body {:type :server-timeout
|
||||||
|
:code :idle-in-transaction-timeout
|
||||||
|
:hint (ex-message error)}}
|
||||||
|
|
||||||
|
:else
|
||||||
|
{:status 500
|
||||||
|
:body {:type :server-timeout
|
||||||
|
:hint (ex-message error)
|
||||||
|
:state state}})))
|
||||||
|
|
||||||
(defn handle
|
(defn handle
|
||||||
[error req]
|
[error req]
|
||||||
|
|
Loading…
Add table
Reference in a new issue