This is an automated email from the ASF dual-hosted git repository. doebele pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push: new 65f6dccc EMPIREDB-456: WebApplication: improved exception handling 65f6dccc is described below commit 65f6dccc57d7b69fa0aa1407fc15c68892946215 Author: Rainer Döbele <doeb...@apache.org> AuthorDate: Mon Apr 28 12:07:04 2025 +0200 EMPIREDB-456: WebApplication: improved exception handling --- .../org/apache/empire/jsf2/app/WebApplication.java | 32 +++++++++++++++++++--- .../exceptions/InvalidPropertyException.java | 6 ++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java index 2fa22955..22dba752 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java @@ -58,6 +58,7 @@ import org.apache.empire.jsf2.controls.TextInputControl; import org.apache.empire.jsf2.impl.FacesImplementation; import org.apache.empire.jsf2.impl.ResourceTextResolver; import org.apache.empire.jsf2.pages.Page; +import org.apache.empire.jsf2.pages.PageDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -397,9 +398,12 @@ public abstract class WebApplication // log source String origin = (source!=null ? source.getPageDefinition().getPageBeanName() : "[Unknown]"); log.error("Fatal error of type {} from \"{}\": {}: {}", e.getClass().getName(), origin, e.getMessage()); + + // check handled + boolean handled = (context.getMaximumSeverity()==FacesMessage.SEVERITY_ERROR); // For page errors, give the ExceptionHandler a chance to handle - if (source!=null) + if (!handled && source!=null) { // Queue event ExceptionQueuedEventContext event = new ExceptionQueuedEventContext(context, e, null, context.getCurrentPhaseId()); @@ -411,9 +415,29 @@ public abstract class WebApplication if (context.getResponseComplete()) return; } - - // If all has failed, redirect to ContextPath (root) - redirectDirectly(context, StringUtils.EMPTY); + + // Find message + FacesMessage facesMsg = null; + Iterator<FacesMessage> messages = context.getMessages(); + while (messages.hasNext()) + { + FacesMessage msg = messages.next(); + if (msg.getSeverity()==FacesMessage.SEVERITY_ERROR) + { // found + facesMsg = msg; + break; + } + } + if (facesMsg==null) + facesMsg = getFacesErrorMessage(context, origin, e); + // Set Session Message + ExternalContext ec = context.getExternalContext(); + ec.getSessionMap().put(Page.SESSION_MESSAGE, facesMsg); + + // If parentPage is null then redirect to ContextPath (root) + PageDefinition parentPage = (source!=null ? source.getParentPage() : null); + String redirectUrl = (parentPage!=null ? parentPage.getOutcome().toString() : StringUtils.EMPTY); + redirectDirectly(context, redirectUrl); } /** diff --git a/empire-db/src/main/java/org/apache/empire/exceptions/InvalidPropertyException.java b/empire-db/src/main/java/org/apache/empire/exceptions/InvalidPropertyException.java index 2b120b0b..1ac7c49f 100644 --- a/empire-db/src/main/java/org/apache/empire/exceptions/InvalidPropertyException.java +++ b/empire-db/src/main/java/org/apache/empire/exceptions/InvalidPropertyException.java @@ -25,15 +25,17 @@ public class InvalidPropertyException extends EmpireException { private static final long serialVersionUID = 1L; + private static final String NULL = "NULL"; + public static final ErrorType errorType = new ErrorType("error.propertyInvalid", "The property {0} is not valid. Current value is {1}."); public InvalidPropertyException(String property, Object value, Exception cause) { - super(errorType, new String[] { property, StringUtils.valueOf(value) }, cause); + super(errorType, new String[] { property, StringUtils.toString(value, NULL) }, cause); } public InvalidPropertyException(String property, Object value) { - super(errorType, new String[] { property, StringUtils.valueOf(value) }); + super(errorType, new String[] { property, StringUtils.toString(value, NULL) }); } }