A static error page by definition cannot be changed dynamically to include 
additional information. You could instead redirect to that page and add a 
query string to the URL with the error message or code, though that would 
be visible in the browser address bar. Alternatively, you could use a 
dynamic error handler, though it may be tricky to communicate the error 
message to the error handling action (maybe store it in the user session, 
assuming it is in the same app).

Another option would be to simply render the alternative HTML page from 
within the controller:

def myaction():
    if not request.vars.client_id:
        error_page = response.render('default/error.html',
                                     dict(message='client_id parameter 
missing'))
        raise HTTP(400, error_page)
    ...

That could also be abstracted into a helper function:

def error_check():
    message = None
    if not request.vars.client_id:
        message = 'client_id parameter missing'
    elif [check for other errors]:
        message = 'other error message'
    if message:
        error_page = response.render('default/error.html',
                                     dict(message='client_id parameter 
missing'))
        raise HTTP(400, error_page)

Anthony


On Wednesday, September 2, 2015 at 10:30:51 AM UTC-4, Alex wrote:
>
> On my server I use a routes.py file to route HTTP errors to static error 
> pages. e.g.
> routes_onerror = [
>      (r'myapp/400', r'/myapp/error/http400'),
> ...
>
> In a controller I check user input and then raise HTTP errors if something 
> is wrong. e.g.
> if not request.vars.client_id:
>     raise HTTP(400, 'client_id parameter is missing')
>
>
> When I test my code locally I don't have error re-routing and thus I 
> directly see the message from the http error. When a check goes wrong on 
> the server only the static error page is shown which is fine for the user. 
> But for me it is very hard to find out which check went wrong and where the 
> error was raised.
>
> Is it possible to access the HTTP error body in my error controller? then 
> I could display it in a hidden element on the error page. Another option 
> would be if I could somehow avoid the error routing, e.g. by adding a 
> request parameter (?disable_routes=1) or something like that. Any ideas how 
> I could do this?
>
> thanks for your help,
> Alex
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to