How to Handle Uncaught Exceptions in GlobalSettings.onError

Asked 2 years ago, Updated 2 years ago, 128 views

Is there any way to comprehensively capture the supplementation of exceptions in play framework (2.3)?

GlobalSettings.onError captures exceptions during normal request processing.

defaction=Action{
 Ok.chunked (Enumerator.outputStream(o=>csvWrite(o))>>Enumerator.eof)
}
defcsvWrite(o:OutputStream) = through new Exception()

If you want to export asynchronously using Enumerator.outputStream, for example, in , an exception occurs inside it (csvWrite in the example above), the console will only display an error at the debug level.

What I want to do is catch an exception and throw up a log with a stack trace at the error level (and send an alert email, etc.).Of course, I can try-catch it individually, but I think I'll forget it somewhere. So I'm looking for a mechanism that would work if I set up one (or some) for the entire application. Do you have one?

scala playframework

2022-09-30 20:28

1 Answers

I'm not very confident, and there are some terrible examples that I probably can't save with this pattern

(Example https://github.com/playframework/playframework/pull/3707)

However, one thing to consider is that Scala's own ExecutionContext has a mechanism to handle exceptions that were not caught regardless of play, so would you like to use the explicitly set ExecutionContext?

By default, the implementation should only be used to printStackTrace.


2022-09-30 20:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.