Custom Error Page c/w Cause and Stacktrace Information

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.ibm.com/xsp/core xsdxp://localhost/xsp~core.xsd"
	pageTitle="${javascript:database.getTitle() + ' | Error'}">
	<xp:div>
		<xp:br></xp:br>
		<xp:br></xp:br>
		<xp:label style="font-weight:bold;font-size:12pt" value="An error has occurred:"></xp:label>
		<xp:br></xp:br>
		<xp:br></xp:br>
		<xp:text escape="true" id="computedField1">
			<xp:this.value>
				<![CDATA[#{javascript:
					var output = requestScope.error.toString()+"\n\n";
					if(requestScope.error instanceof com.ibm.xsp.exception.XSPExceptionInfo){
						var codeSnippet = requestScope.error.getErrorText(); 
						var control = requestScope.error.getErrorComponentId();
						var cause = requestScope.error.getCause();
						output += "In the control : " + control + "\n\n";
						if(cause instanceof com.ibm.jscript.InterpretException){
							var errorLine = cause.getErrorLine();
							var errorColumn = cause.getErrorCol();
							output += "At line " + errorLine;
							output += ", column " + errorColumn + " of:\n";
						}else{
							output += "In the script:\n";
						}
						output += codeSnippet;
					}
					return output;
				}]]>
			</xp:this.value>
		</xp:text>
		<xp:br></xp:br>
		<xp:br></xp:br>
		<xp:text escape="false" id="computedField" style="font-size:10pt">
			<xp:this.value>
				<![CDATA[#{javascript:var stackTrace = "";
					var trace = requestScope.error.getStackTrace();
					for(var i = 0; i < trace.length; i++){
						stackTrace += trace[i] + "<br/>";
					}
					return stackTrace;
				}]]>
			</xp:this.value>
		</xp:text>
	</xp:div>
</xp:view>





Use this snippet to create a custom error XPage.  Remember to set the Error Page in the Application Properties to point at your new custom error XPage.

If an exception occurs in your application, you'll see error output in the custom error page like this example:


An error has occurred:

com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression In the control : computedField7 At line 1, column 19 of: #{javascript:nonexistentObject.isDebugMode()}

com.ibm.xsp.binding.javascript.JavaScriptValueBinding.getValue(JavaScriptValueBinding.java:132)
javax.faces.component.UIOutput.getValue(UIOutput.java:159)
com.ibm.xsp.util.FacesUtil.convertValue(FacesUtil.java:1120)
com.ibm.xsp.renderkit.html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:97)
com.ibm.xsp.renderkit.ReadOnlyAdapterRenderer.encodeEnd(ReadOnlyAdapterRenderer.java:180)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:1005)
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:856)
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:851)
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:851)
com.ibm.xsp.util.FacesUtil.renderComponent(FacesUtil.java:851)
com.ibm.xsp.component.UIViewRootEx._renderView(UIViewRootEx.java:1317)
com.ibm.xsp.component.UIViewRootEx.renderView(UIViewRootEx.java:1255)
com.ibm.xsp.application.ViewHandlerExImpl.doRender(ViewHandlerExImpl.java:641)
com.ibm.xsp.application.ViewHandlerExImpl._renderView(ViewHandlerExImpl.java:320)
com.ibm.xsp.application.ViewHandlerExImpl.renderView(ViewHandlerExImpl.java:335)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:103)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:120)
com.ibm.xsp.controller.FacesControllerImpl.render(FacesControllerImpl.java:264)
com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:248)
com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:205)
com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1281)
com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:847)
com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1265)
com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:661)
com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:481)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:350)
com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:306)
com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)

XPages
Tony McGuckin
May 8, 2012 4:27 PM
Rating
577

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...