Skip to content

Commit

Permalink
Merge pull request #2824 from jonathannewman/PE-37145/7.x/better-exce…
Browse files Browse the repository at this point in the history
…ption-messaging

(PE-37145) ensure schema failures are verbosely logged
  • Loading branch information
steveax authored Feb 16, 2024
2 parents cda8c13 + 8b5dcc7 commit 158d7d6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/clj/puppetlabs/puppetserver/jruby_request.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@
(= (:kind x)
:puppetlabs.services.jruby-pool-manager.jruby-core/jruby-timeout)))

(defn schema-error?
"Determine if the supplied slingshot message is for a JRuby borrow timeout."
[x]
(when (map? x)
(= (:type x)
:schema.core/error)))

(defn output-error
[{:keys [uri]} {:keys [msg]} http-status]
(log/error (i18n/trs "Error {0} on SERVER at {1}: {2}" http-status uri msg))
(ringutils/plain-response http-status msg))

(defn output-map-error
[{:keys [uri]} error http-status]
(log/error (i18n/trs "Error {0} on SERVER at {1}: {2}" http-status uri error))
(ringutils/json-response http-status error))

(defn wrap-with-error-handling
"Middleware that wraps a JRuby request with some error handling to return
the appropriate http status codes, etc."
Expand All @@ -34,7 +46,9 @@
(catch jruby-timeout? e
(output-error request e 503))
(catch ringutils/service-unavailable? e
(output-error request e 503)))))
(output-error request e 503))
(catch schema-error? e
(output-map-error request e 500)))))

(defn wrap-with-jruby-instance
"Middleware fn that borrows a jruby instance from the `jruby-service` and makes
Expand Down

0 comments on commit 158d7d6

Please sign in to comment.