How to not return ticket issue HTML but a custom error?

164 views
Skip to first unread message

Ty oc

unread,
Sep 6, 2016, 10:43:19 AM9/6/16
to web2py-users
Still I need to log the ticket issue so we know what is happening (we will be watching for errors to show on the admin webapp), but we dont want the error to be like the HTML that is always show to the user.

I want to return a one of the following depending on where Im returning it (a page in the web app or a request of a service)

  • for the service
    • {"error":"see ticket xyz"}
  • for the HTML webpage
    • General error, return home "here".



Anthony

unread,
Sep 6, 2016, 12:17:58 PM9/6/16
to web2py-users

Ty oc

unread,
Sep 19, 2016, 5:02:11 PM9/19/16
to web2py-users
Where exactly I need to put this file?

I have tried

error_message = '<html><body><h1>%s-------</h1></body></html>'
error_message_ticket = '''<html><body><h1>Internal error</h1>
Ticket issued: <a href="/admin/default/ticket/%(ticket)s"
target="_blank">%(ticket)s</a>------</body></html>'''

routes_onerror = [
('init/400', '/backend/default/index'),
('init/*', '/backend/default/index'),
('*/404', '/backend/default/index'),
('*/*', '/backend/error/report')
]



error_handler = dict(application='backend',
controller='error',
function='report')


Still no correct message displayed if I cause a 500 server error. Where do I activate it?

I mean, even debugging passes over the redirector inside web2py and see nothing on those variables causing normal behaviour on the branch on rewrite.py

if status >= 399 and THREAD_LOCAL.routes.routes_onerror:


so....

Anthony

unread,
Sep 19, 2016, 6:51:28 PM9/19/16
to web2py-users
routes.py goes in the root /web2py folder. Be sure to restart the server or reload routes (via admin). Also, make sure you don't actually have an error somewhere in your error handling app.

Ty oc

unread,
Sep 20, 2016, 11:06:10 AM9/20/16
to web2py-users
I thought it was a per app configuration.

Ty oc

unread,
Sep 20, 2016, 11:22:34 AM9/20/16
to web2py-users
I mean, we have other web2py apps there, I dont want to modify the default behaviour of the other ones, only this "backend" app.

Ty oc

unread,
Sep 20, 2016, 12:20:48 PM9/20/16
to web2py-users
Well also now I got it (still not per app)... but the problem Im having is that I want to return a json, but Im getting the full HTML response  with a body and all that.

If I use

error_handler = dict(application='backend',
controller='error',
function='report')

Nothing changes. So I have setup


routes_onerror = [
('init/400', '/backend/default/index'),
('init/*', '/backend/default/index'),
('*/404', '/backend/default/index'),
('*/*', '/backend/error/report')
]


I have as response this HTML instead of the json


<html><head><link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" ></head><body data-pinterest-extension-installed="ff1.37.9"><pre>{&amp;#x27;message&amp;#x27;: &amp;#x27;Error interno&amp;#x27;}</pre></body></html>

Dave S

unread,
Sep 20, 2016, 2:24:30 PM9/20/16
to web...@googlegroups.com


On Tuesday, September 20, 2016 at 9:20:48 AM UTC-7, Ty oc wrote:
Well also now I got it (still not per app)... but the problem Im having is that I want to return a json, but Im getting the full HTML response  with a body and all that.

Are  you setting content type to json?  That came up recently in a thread.  You can (AIUI) either set just the header string and use response.json(), or use generic.json as a template example.
<URL:https://groups.google.com/d/msg/web2py/8D4IgBy_rAA/bfdBJuYDDwAJ>

/dps

Dave S

unread,
Sep 20, 2016, 2:31:22 PM9/20/16
to web2py-users


On Tuesday, September 20, 2016 at 9:20:48 AM UTC-7, Ty oc wrote:
Well also now I got it (still not per app)...

Well, the book says routes_onerror can specify a global mapping, an app mapping, an error code mapping, or app+err.
<URL:http://web2py.com/books/default/chapter/29/04/the-core#Routes-on-error>

Just above that, in the tail of the pattern-based router description, it talks about how to have the base routes.py direct to an app routes.py for handling the other URLs of a specific application.

/dps




 

Anthony

unread,
Sep 20, 2016, 5:20:00 PM9/20/16
to web2py-users, web2py-developers
On Tuesday, September 20, 2016 at 12:20:48 PM UTC-4, Ty oc wrote:
Well also now I got it (still not per app)... but the problem Im having is that I want to return a json, but Im getting the full HTML response  with a body and all that.

If I use

error_handler = dict(application='backend',
controller='error',
function='report')

Nothing changes. So I have setup

Yes, it seems the documentation is way off regarding error_handler. As far as I can tell, the only time that does anything is when you request a non-existent application, in which case, it does a full HTTP redirect to the application specified in error_handler, with the name of the originally requested application in request.args(0). Given its functionality, it would be better named something like missing_app_handler.

Anthony

Anthony

unread,
Sep 20, 2016, 5:21:04 PM9/20/16
to web2py-users


routes_onerror = [
('init/400', '/backend/default/index'),
('init/*', '/backend/default/index'),
('*/404', '/backend/default/index'),
('*/*', '/backend/error/report')
]


I have as response this HTML instead of the json


<html><head><link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" ></head><body data-pinterest-extension-installed="ff1.37.9"><pre>{&amp;#x27;message&amp;#x27;: &amp;#x27;Error interno&amp;#x27;}</pre></body></html>

Is it possible there is an error in the backend app itself?

Anthony

Anthony

unread,
Sep 20, 2016, 5:22:50 PM9/20/16
to web2py-users
On Tuesday, September 20, 2016 at 11:22:34 AM UTC-4, Ty oc wrote:
I mean, we have other web2py apps there, I dont want to modify the default behaviour of the other ones, only this "backend" app.

El martes, 20 de septiembre de 2016, 10:06:10 (UTC-5), Ty oc escribió:
I thought it was a per app configuration.

El lunes, 19 de septiembre de 2016, 17:51:28 (UTC-5), Anthony escribió:
routes.py goes in the root /web2py folder. Be sure to restart the server or reload routes (via admin). Also, make sure you don't actually have an error somewhere in your error handling app.

In routes_onerror, you can specify both the app and the error code (or use wildcards for either).

Anthony
Reply all
Reply to author
Forward
0 new messages