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):
![SS-2014-03-13_16.43.30.png](/android/forum/proxy.php?image=http%3A%2F%2Fwww.b4x.com%2Fbasic4android%2Fimages%2FSS-2014-03-13_16.43.30.png&hash=04477ad49360d6ba8db53302d84efe54)
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)
![SS-2014-03-13_16.52.43.png](/android/forum/proxy.php?image=http%3A%2F%2Fwww.b4x.com%2Fbasic4android%2Fimages%2FSS-2014-03-13_16.52.43.png&hash=58778430e329e7128631a658a2092ee5)
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")