Starting from B4J v1.80 you can configure custom error pages. This means that instead of the default error page:
You can show any page you like. You have two options, you can use a static error page or a handler to handle the error. The advantage of a handler is that you can show a custom message based on the error.
We need to configure the custom pages before the server is started. The configuration is done with a Map that ties the error pages to the http error codes: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
For example, with this code we set two static error pages that will be loaded from the static resources folder:
The URL can point to a handler instead of a static file.
In that case the status code and error message can be retrieved from the response object that is passed to the Handle method (ServletResponse.StatusCode and ServletResponse.ErrorReason).
You can also define a global error page that will catch all the errors (that were not handled):
You can show any page you like. You have two options, you can use a static error page or a handler to handle the error. The advantage of a handler is that you can show a custom message based on the error.
We need to configure the custom pages before the server is started. The configuration is done with a Map that ties the error pages to the http error codes: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
For example, with this code we set two static error pages that will be loaded from the static resources folder:
B4X:
Dim err As Map
err.Initialize
err.Put(404, "/404.html") 'page not found
err.Put(500, "/500.html") 'server error
srvr.SetCustomErrorPages(err)
The URL can point to a handler instead of a static file.
In that case the status code and error message can be retrieved from the response object that is passed to the Handle method (ServletResponse.StatusCode and ServletResponse.ErrorReason).
You can also define a global error page that will catch all the errors (that were not handled):
B4X:
err.Put("org.eclipse.jetty.server.error_page.global", "/page_that_will_handle_all_errors.html")