Mar 13, 2014 Replies: 6 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: Code: Copy 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): Code: Copy err.Put("org.eclipse.jetty.server.error_page.global", "/page_that_will_handle_all_errors.html") Click to expand...
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: Code: Copy 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): Code: Copy err.Put("org.eclipse.jetty.server.error_page.global", "/page_that_will_handle_all_errors.html")
W wl Well-Known Member Licensed User Longtime User Mar 13, 2014 #2 Any chance of some other extra's, such as support for cookies or HTML templates (freemarker) ? Thanks Last edited: Mar 13, 2014
Any chance of some other extra's, such as support for cookies or HTML templates (freemarker) ? Thanks
Erel B4X founder Staff member Licensed User Longtime User Mar 14, 2014 #3 This is not the place to discuss other features... Cookies and user sessions are supported in v1.80: B4J v1.80 BETA is released
This is not the place to discuss other features... Cookies and user sessions are supported in v1.80: B4J v1.80 BETA is released
tchart Well-Known Member Licensed User Longtime User Jun 26, 2015 #4 Erel said: The URL can point to a handler instead of a static file. Click to expand... Erel, can you provide a code sample for handling errors using a handler? I cant seem to figure it out. Which URL are you referring to?
Erel said: The URL can point to a handler instead of a static file. Click to expand... Erel, can you provide a code sample for handling errors using a handler? I cant seem to figure it out. Which URL are you referring to?
Erel B4X founder Staff member Licensed User Longtime User Jun 26, 2015 #5 Instead of redirecting to /404.html you can redirect to /somehandler. In the main module add this handler: Code: Copy srvr.AddHandler("/somehandler", "SomeHandler", False)
Instead of redirecting to /404.html you can redirect to /somehandler. In the main module add this handler: Code: Copy srvr.AddHandler("/somehandler", "SomeHandler", False)
tchart Well-Known Member Licensed User Longtime User Nov 23, 2020 #7 Just a note for anyone who comes across this tutorial, custom pages for 500 errors do not work in debug mode.
Just a note for anyone who comes across this tutorial, custom pages for 500 errors do not work in debug mode.