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
RHDM-919: Improved error messages #238
RHDM-919: Improved error messages #238
Conversation
63fa9ef
to
a738b9f
Compare
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.
Besides minor issues, LGTM. Great job 👍!
...-gwtui/src/main/java/org/optaweb/employeerostering/gwtui/client/exception/RESTException.java
Show resolved
Hide resolved
...rces/org/optaweb/employeerostering/gwtui/client/resources/i18n/OptaWebUIConstants.properties
Outdated
Show resolved
Hide resolved
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.
Please see my comments in line. Apart from those, there is no test coverage showing the exception handling works as expected.
try { | ||
return objectMapper.writeValueAsString(serverSideException); | ||
} catch (JsonProcessingException e) { | ||
return "{}"; |
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.
The information about the exception in JSON serialization has not been propagated anywhere. I would expect to at least log the exception and inform the client that e.g. "There was an issue with retrieving the root cause, due to...more information can be found in a server log."
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.
This is a difficult case: the client is expecting a ServerException JSON object. Trying to serialize the exception could cause another exception (example: objectMapper is null). So we either need to hard code a ServerException JSON object for this case (issue: fragile) or have some way to indicate the error to the client (so we don't try to deserialize the error message as a JSON object). Perhaps I can use different error codes to indicate different cases. WDYT?
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.
My suggestion was to communicate towards the client that there was an issue, but its serialization failed too - find more information in server log. Basically providing as much information as possible, in a nice format.
Right now if the serialization fails, client gets just an empty JSON object and there is nothing in the server log either.
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.
PLAIN_TEXT MediaType is now used when Exception serialization fails (as well as logging the error to the server), and a message telling the user to check the server logs for more details is now shown.
ObjectMapper objectMapper = objectMapperProvider.getContext(ServerSideException.class); | ||
ServerSideException serverSideException; | ||
if (exception instanceof IllegalArgumentException) { | ||
serverSideException = new ServerSideException(exception, "ServerSideException.illegalArgument", |
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.
Suggestions: String literals - especially those with some specific meaning - are usually better to declare as constants.
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.
Might move the different exception types/i18n keys to an enum, and make the enum extract the ServerSideException from the Exception.
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.
Enum sounds good, not sure what you mean about the extraction of the ServerSideException. Would you maybe include some gist or update the PR to illustrate it?
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.
PR Updates; extraction refers to creating the ServerSideExceptionInfo for a given exception (see ExceptionMapping class).
...a/org/optaweb/employeerostering/gwtui/client/gwtjackson/ServerSideExceptionDeserializer.java
Outdated
Show resolved
Hide resolved
...a/org/optaweb/employeerostering/gwtui/client/gwtjackson/ServerSideExceptionDeserializer.java
Outdated
Show resolved
Hide resolved
...a/org/optaweb/employeerostering/gwtui/client/gwtjackson/ServerSideExceptionDeserializer.java
Outdated
Show resolved
Hide resolved
...shared/src/main/java/org/optaweb/employeerostering/shared/exception/ServerSideException.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/optaweb/employeerostering/server/common/jaxrs/OptaWebExceptionMapper.java
Outdated
Show resolved
Hide resolved
...a/org/optaweb/employeerostering/gwtui/client/pages/rotation/RotationPageViewportBuilder.java
Outdated
Show resolved
Hide resolved
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.
Please see the comments - mainly about suggested test coverage.
} | ||
|
||
@Override | ||
public void onFailure(final Throwable throwable) { |
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.
Would you please explain why is the behaviour of onError
different than of onFailure
?
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.
onError
occurs when we have a Response (which may have a Json Body and if so contain a Server Exception); onFailure
occurs when we only have a Throwable (and thus cannot extract a Server Exception from it).
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.
Thank you
...-gwtui/src/main/java/org/optaweb/employeerostering/gwtui/client/exception/RESTException.java
Outdated
Show resolved
Hide resolved
...a/org/optaweb/employeerostering/gwtui/client/gwtjackson/ServerSideExceptionDeserializer.java
Show resolved
Hide resolved
* @param <K> The type of the key element in the Hierarchy | ||
* @param <V> The type of the value element in the Hierarchy | ||
*/ | ||
public class HierarchyTree<K, V> { |
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.
@Christopher-Chianelli @ge0ffrey was it the plan to fully implement https://issues.jboss.org/browse/PLANNER-933 now? Given we want to rewrite most of the application, we should think twice about adding every such a complex piece of code.
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.
I think the rewrite apply mostly to the client code (i.e. most of the server code will remain the same). HierarchyTree
is server code, so the probability of it changing in the rewrite is low.
@Christopher-Chianelli one more thing; does the dialog showing a full stacktrace have to display the error icon? Right now there is no space between the picture and text; I think the presence of the picture is questionable. |
@rsynek No, I think it was requested for there to be an error icon in the original Error Popup, which the Stack Trace uses. However, I can easily remove/change it. |
I am not a UX expert, but I cannot see any added value by having the icon there. As the stack trace text is closely attached to the icon, it doesn't look really well. |
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.
So summarize the remaining concerns:
- I suggest adding tests also for the OptaWebExceptionMapper
- please consider removing the icon from the detailed error screen
Otherwise looks good and we can merge. Thanks!
* is the "next token" (i.e. if the current token in the parser is 10, | ||
* then nextInt() should return 10) | ||
*/ | ||
public class TestJsonReaderImpl implements JsonReader { |
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.
It's a pity there is no common interface (I haven't found any) between gwt-jackson and jackson-core, that would suit our needs. That way you could just switch the implementations.
import org.optaweb.employeerostering.shared.exception.ServerSideExceptionInfo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Provider | ||
public class OptaWebExceptionMapper implements ExceptionMapper<Exception> { |
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.
This class has no test coverage - please take a look at the SonarCloud coverate report. If you have any troubles seeing the report, let me know, I will be happy to help.
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.
It is partially covered in the integration test (although we don't inspect the JSON data in the integration test). I can add some JSON inspection tests to the integration tests (as well as create a unit test for it).
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.
Thanks for the additional coverage and various improvements discussed in this PR.
LGTM.
Modified the backend to return a JSON containing information about the exception (including an i18n Translation Key) when an exception occurs.