-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API exception responses should contain more detail #496
API exception responses should contain more detail #496
Conversation
I think that actually is the case.
The The
Yes, sounds worth looking into. That's just about the first API call that the web client makes, and the response tells the client what URL to connect to for the websocket notification channel, so if any exception occurs here then 1) something is definitely wrong with the Cryostat deployment, 2) the web-client is going to be only partially functional for the user, so they should be given some proper information that something is wrong and some hint about what the issue is. |
Thanks, I'll check it out and let you know what I find.
Should I create an issue for refactoring |
@@ -152,6 +152,10 @@ public void start() throws FlightRecorderException, SocketException, UnknownHost | |||
? exception.getPayload() | |||
: exception.getMessage(); | |||
|
|||
if (exception.getCause() != null) { | |||
payload += ": " + exception.getCause().getMessage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and simple :-)
I think, from the screenshot you've provided and from what I remember of how I implemented the various exception handling paths that lead here, that this is probably already a sufficient fix for the issue.
But, it might be possible to enhance this message further - it's worth experimenting with at least, although in the end we may just come back to the current solution you have here.
Take a look at this utility class: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/exception/ExceptionUtils.html
We already have this as a dependency and use this class in a couple of other places.
The methods getMessage
and getThrowables
in particular could be neat here to provide even more context around these exceptions.
Yes, this is definitely out of scope of this issue/this PR. I do think it's a work item worth adding to the backlog, so do go ahead and file an issue ( |
The console is showing a In To fix this, we might need to edit the web client to check for server errors before parsing a url from the json response? |
Nice investigation, that explanation makes sense to me. I've filed a corresponding bug in the -web repo. |
Nice. Here's what I observed just now, when I did the same modification to --- a/src/main/java/io/cryostat/net/web/WebServer.java
+++ b/src/main/java/io/cryostat/net/web/WebServer.java
@@ -251,7 +251,7 @@ public class WebServer {
public String getDownloadURL(JFRConnection connection, String recordingName)
throws URISyntaxException, IOException {
- return new URIBuilder(getHostUri())
+ String s = new URIBuilder(getHostUri())
.setScheme(server.isSsl() ? "https" : "http")
.setPathSegments(
"api",
@@ -263,6 +263,7 @@ public class WebServer {
.build()
.normalize()
.toString();
+ throw new URISyntaxException(s, "just because");
} I think this looks pretty good and definitely gives good context as to what the reason for the exception was, without forcing the user to go look in the Cryostat log. |
Resolves #435. Exceptions that get re-thrown as a
new HttpStatusException(500, e)
by a handler get caught and handled byWebServer
. Thenew HttpStatusException
does not contain an error message itself, but theWebServer
can append the underlying exception message to the API exception responses withe.getCause().getMessage()
:Slightly unrelated question: Why does JaCoCo show that the
WebServer
failure handler isn't covered by any unit tests? I found an integration test forClientUrl
that only tests for successful scenarios.