Skip to content
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

Merged
merged 8 commits into from May 28, 2019

Conversation

Christopher-Chianelli
Copy link
Collaborator

Modified the backend to return a JSON containing information about the exception (including an i18n Translation Key) when an exception occurs.

Copy link

@Fonifan Fonifan left a 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 👍!

Copy link
Collaborator

@rsynek rsynek left a 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 "{}";
Copy link
Collaborator

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."

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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",
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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).

Copy link
Collaborator

@rsynek rsynek left a 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) {
Copy link
Collaborator

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 ?

Copy link
Collaborator Author

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).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

* @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> {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@rsynek
Copy link
Collaborator

rsynek commented May 20, 2019

@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.

@Christopher-Chianelli
Copy link
Collaborator Author

@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.

@rsynek
Copy link
Collaborator

rsynek commented May 23, 2019

@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.

Copy link
Collaborator

@rsynek rsynek left a 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 {
Copy link
Collaborator

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> {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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).

Copy link
Collaborator

@rsynek rsynek left a 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.

@Christopher-Chianelli Christopher-Chianelli merged commit d6b6479 into kiegroup:master May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants