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

RA-1889:Return Relatively Formatted Error Instead Of Returning Full Exception #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sherrif10
Copy link
Member

@sherrif10 sherrif10 commented Feb 10, 2021

https://issues.openmrs.org/browse/RA-1889
cc @dkayiwa @ibacher @mozzy11 kindly review thanks
WHAT I DID
Added a groovy page that will be returned
Added a NullPointerclass to handle exception
Still Under Testing

@sherrif10 sherrif10 marked this pull request as ready for review February 10, 2021 20:39
@sherrif10 sherrif10 changed the title RA-1889:Return Relatively Formatted Error Message RA-1889:Return Relatively Formatted Error Instead Of Returning Full Exception Feb 10, 2021
throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm());
message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm());
log.warn("Active drugs are cannot be editted");
model.addAttribute("htmlForm", htmlForm);
Copy link
Member

Choose a reason for hiding this comment

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

@sherrif10 already here the form be null , why then add a null to the model ??

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @mozzy11 , Wanted to return a model rathan null, let me re-correct it

if (htmlForm == null) {
throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm());
message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm());
Copy link
Member

Choose a reason for hiding this comment

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

i gues this should take in a message code ,

Copy link
Member Author

Choose a reason for hiding this comment

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

It depends, it takes in both Actually message codes would be also another good idea since we are trying to hide the exception hence returning a readable message format

<html>
<body>
<p>Application has encountered an error. Please contact support on ...</p>
<% out << " ooppsss!!!! Active drugs cannot be edittted!" %>
Copy link
Member

Choose a reason for hiding this comment

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

what is this for ?? and how do you expect it to work anyway??

Copy link
Member Author

Choose a reason for hiding this comment

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

This should ideally be returned as an error page like returned in the controller class

Copy link
Member

Choose a reason for hiding this comment

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

Yes, instead of "active drugs cannot be editted", don't we want to just return the message below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thanks have collected the error return message

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

I'm fine with the idea of returning a "nicer" error page, but I don't think this is the right way to go about it?

Also, I'm not sure if the fact that encounter.form is null is due to the fact one is trying to edit active drugs? It certainly isn't the only way this error could occur?

I added some comments on the ticket as well.

@mozzy11
Copy link
Member

mozzy11 commented Feb 11, 2021

@mogoodrich i dont think its very necesary to return a full page , Why not just a simple ui message ??

@sherrif10
Copy link
Member Author

Thanks @mogoodrich @mozzy11 sure simple ui message would ideally be worth it , though havent seen any ui error message example , feel free to share with me any example i also agree that my code need to be refactored.One more thing to consider is to use exceptionHandlers which can handle exceptions

<html>
<body>
<p>Application has encountered an error. Please contact support on ...</p>
<% out << " ooppsss!!!! Active drugs cannot be edittted!" %>
Copy link
Member

Choose a reason for hiding this comment

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

Yes, instead of "active drugs cannot be editted", don't we want to just return the message below?

if (htmlForm == null) {
throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm());
log.warn("Active drugs are cannot be editted");
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be "encounter.form is not an HTML Form"? that's the real error here, not that active drugs can't be edited.

Copy link
Member Author

Choose a reason for hiding this comment

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

Resolved thanks


@ExceptionHandler(value= NullPointerException.class)
public String HandleNullPointerException(Exception e) {
log.warn("encounter.form is not an HTML Form");
Copy link
Member

Choose a reason for hiding this comment

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

doesn't this catch any Null Pointer Exception? How do we know that the "encounter.form" NPE was the one that caused it?

Copy link
Member Author

@sherrif10 sherrif10 Feb 11, 2021

Choose a reason for hiding this comment

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

Have changed it to illegalArgumentException, this method would handle any exception that would occur when any api with in the controller class returns an exception is called

<html>
<body>
<p>Application has encountered an error. Please contact support on ...</p>
<% out << "encounter.form is not an HTML Form" %>
Copy link

@HerbertYiga HerbertYiga Feb 15, 2021

Choose a reason for hiding this comment

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

is this the error you are returning? down your controller ,add the error message to an attribute for example errorMessage and access it from the gsp as ${errorMessage }

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks @HerbertYiga , ,Am not well convinced with this approach and am sure there is a clean way of doing this which am looking forward too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants