Skip to content

Commit

Permalink
RA-1889:Return Relativively Formatted Error Message
Browse files Browse the repository at this point in the history
  • Loading branch information
sherrif10 committed Feb 10, 2021
1 parent d015d5a commit 37aa36a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.openmrs.module.htmlformentryui.page.controller.htmlform;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.commons.lang.StringUtils;
import org.openmrs.Encounter;
import org.openmrs.api.AdministrationService;
import org.openmrs.messagesource.MessageSourceService;
import org.openmrs.module.emrapi.patient.PatientDomainWrapper;
import org.openmrs.module.htmlformentry.HtmlForm;
import org.openmrs.module.htmlformentry.HtmlFormEntryService;
Expand All @@ -11,9 +15,18 @@
import org.openmrs.ui.framework.annotation.InjectBeans;
import org.openmrs.ui.framework.annotation.SpringBean;
import org.openmrs.ui.framework.page.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestParam;

public class ViewEncounterWithHtmlFormPageController {

private static final Log log = LogFactory.getLog(ViewEncounterWithHtmlFormPageController.class);

@Autowired
private MessageSourceService messageSourceService;

private String message;

public void get(@RequestParam("encounter") Encounter encounter,
@RequestParam(value = "showPatientHeader", defaultValue = "true") boolean showPatientHeader,
Expand Down Expand Up @@ -52,8 +65,16 @@ public void get(@RequestParam("encounter") Encounter encounter,
model.addAttribute("showPatientHeader", showPatientHeader);

HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm());
// HttpSession session = request.getSession();
if (htmlForm == null) {
throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm());
// HttpSession session = request.getSession();
message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm());
log.warn("Active drugs are not supported yet");
// session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, message);
// throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm());
model.addAttribute("htmlForm", htmlForm);


}
model.addAttribute("htmlForm", htmlForm);
}
Expand All @@ -65,5 +86,11 @@ public void get(@RequestParam("encounter") Encounter encounter,
private String fixCase(String word) {
return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase();
}

@ExceptionHandler(value= NullPointerException.class)
public String HandleNullPointerException(Exception e) {
log.warn(message);
return "NullPointerException";
}

}
Empty file.

0 comments on commit 37aa36a

Please sign in to comment.