Skip to content

Commit

Permalink
Merge pull request #64 from jonathannewman/maint/main/add-method-uri
Browse files Browse the repository at this point in the history
(PE-38702) add method and uri to unhandled exception logging
  • Loading branch information
steveax authored Jul 11, 2024
2 parents edaa7b2 + b2f7a7b commit ca6f15d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 2.0.2
# 2.0.4
* add calling method and uri to unhandled exception logging
# 2.0.3
* released with no changes due to issues with licensing in project.clj
# 2.0.2 - unreleased
* update to clj parent 7.3.31
* optimize the `wrap-uncaught-errors` to avoid anonymous functions, and ensure streams are closed
* add new wrappers:
Expand Down
11 changes: 6 additions & 5 deletions src/puppetlabs/ring_middleware/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,14 @@
(catch utils/schema-error? e
(response e)))))))

(defn handle-error-response
[e type]
(defn- handle-error-response
[request e type]
(with-open [baos (ByteArrayOutputStream.)
print-stream (PrintStream. baos)]
(.printStackTrace e print-stream)
(let [msg (trs "Internal Server Error: {0}" (.toString e))]
(log/error (trs "Internal Server Error: {0}" (.toString baos)))
(let [msg (trs "Internal Server Error: {0}" (.toString e))
method (-> request :request-method name str/upper-case)]
(log/error (trs "Internal Server Error for {1} {2}: {0}" (.toString baos) method (:uri request)))
(case type
:json (utils/json-response InternalServiceError
{:kind :application-error
Expand All @@ -234,7 +235,7 @@
(try
(handler request)
(catch Throwable e
(handle-error-response e type))))))
(handle-error-response request e type))))))

(schema/defn ^:always-validate wrap-add-referrer-policy :- IFn
"Adds referrer policy to the header as 'Referrer-Policy: no-referrer' or 'Referrer-Policy: same-origin'"
Expand Down

0 comments on commit ca6f15d

Please sign in to comment.