thanks.

I don't like adding UI Text to URLs as it's too easy for 3rd-parties to
generate URls and have your site serve anything they like :)

Your suggestion of ditching the standard HTTP status codes spurs a thought:
I could drop Web2py's HTTP altogether and just redirect to my own error
handler page. That way HTTP remains untouched and it's clearer that I've
written an alternative implementation.

Has anyone else come across this issue with Web2py's HTTP missing body text?

On Wed, 18 Jan 2017 at 23:18 Anthony <abasta...@gmail.com> wrote:

> On Wednesday, January 18, 2017 at 10:26:10 AM UTC-5, Carl Hunter Roach
> wrote:
>
> To routes.py I have:
>
> routes_onerror = [
> ('*/400', '/app/controller/error_handler')
> ]
>
> So for a raise HTTP(400, "Explanation Text")
>
> and from error_handler() I can get request.vars.code (400, in this
> example).
>
> How can error_hander() get the text "Explanation Text" ?
>
>
> Looking at the internal code, it doesn't look like you can get the "body"
> argument to HTTP() in the error handler. However, here are a couple of
> hacks:
>
> request.wsgi.wsgi_environ['error_message'] = 'Explanation Text'
> raise HTTP(400)
>
> Then in the error handler:
>
> def error_handler():
>     error_message = request.env.error_message
>
> That works because request.wsgi.wsgi_environ is the original WSGI
> environment dictionary for the request, and it gets re-used by the error
> handler (so it ends up in request.env in the error handler).
>
> Alternatively, you can append your error message to request.url, which
> itself is passed to the error handler:
>
> request.url = '%s&error_message=%s' % (request.url, 'Explanation Text')
>
> And in the error handler:
>
> def error_handler():
>     error_message = request.vars.error_message
>
> That is really just adding an additional variable to the query string that
> gets passed to the error handler by embedding the new variable within
> request.url.
>
> Alternatively, if you have a limited number of messages, you can simply
> use a different numeric response code for each case to distinguish the
> errors. You don't have to limit yourself to the standard HTTP response
> codes, as in this case, the code is only used internally and never sent to
> the client (you can set a new response status when finally sending a
> response to the client).
>
>
> Anthony
>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/Mg5kK2AuoMQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
----
Carl D Hunter Roach

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to