librelist archives

« back to archive

Error Handler

Error Handler

From:
Adriano Almeida
Date:
2015-07-24 @ 10:12
Hello!!

Actually I am trying Falcon and I want to control diferent kind of http
errors, like 404 or 500.

I checked the documentation and write the following code:


class Http404Error(Exception):
    @staticmethod
    def handle(ex, req, resp, params):
        description = ('Sorry, 404 Not Found.')
        raise falcon.HTTPError(falcon.HTTP_725, '404 Error', description)


app = falcon.API()
app.add_error_handler(Http404Error)


But this is not working...

Can someone give me some hints?

Regards


-- 
Adriano Almeida

Re: [falcon] Error Handler

From:
Kurt Griffiths
Date:
2015-08-03 @ 19:32
Hi Adriano,

The code linked below is based on your code sample, and should work. Is 
this what you were trying to achieve? I’m happy to help in any way I can.

https://gist.github.com/kgriffs/c9dabe86abad0bdf4791


-Kurt

Re: Error Handler

From:
Adriano Almeida
Date:
2015-08-03 @ 19:45
Thanks Kurt. This answer it's working for a self raised error...

But my problem it's when isn't a controled raised error...

For example when the url it's not defined on falcon...


El lunes, 3 de agosto de 2015, Kurt Griffiths <kurt.griffiths@rackspace.com>
escribió:

> Hi Adriano,
>
> The code linked below is based on your code sample, and should work. Is
> this what you were trying to achieve? I’m happy to help in any way I can.
>
> https://gist.github.com/kgriffs/c9dabe86abad0bdf4791
>
>
> -Kurt
>


-- 
Adriano Almeida

Re: [falcon] Re: Error Handler

From:
Kurt Griffiths
Date:
2015-08-06 @ 15:48
By "the url it's not defined", do you mean there isn’t a route? In that 
case Falcon normally returns 404. Are you looking for a way to customize 
what is returned in that case?

From: <falcon@librelist.com<mailto:falcon@librelist.com>> on behalf of 
Adriano Almeida
Reply-To: "falcon@librelist.com<mailto:falcon@librelist.com>"
Date: Monday, August 3, 2015 at 2:45 PM
To: "falcon@librelist.com<mailto:falcon@librelist.com>"
Subject: [falcon] Re: Error Handler

Thanks Kurt. This answer it's working for a self raised error...

But my problem it's when isn't a controled raised error...

For example when the url it's not defined on falcon...


El lunes, 3 de agosto de 2015, Kurt Griffiths 
<kurt.griffiths@rackspace.com<mailto:kurt.griffiths@rackspace.com>> 
escribió:
Hi Adriano,

The code linked below is based on your code sample, and should work. Is 
this what you were trying to achieve? I’m happy to help in any way I can.

https://gist.github.com/kgriffs/c9dabe86abad0bdf4791


-Kurt


--
Adriano Almeida

Re: [falcon] Re: Error Handler

From:
Ben Demaree
Date:
2015-08-06 @ 22:19
Have you tried this with a different WSGI server? Have seen some that try
and override exception handling for you. uWSGI has been pretty well-behaved.

On Thu, Aug 6, 2015 at 10:48 AM, Kurt Griffiths <
kurt.griffiths@rackspace.com> wrote:

> By "the url it's not defined", do you mean there isn’t a route? In that
> case Falcon normally returns 404. Are you looking for a way to customize
> what is returned in that case?
>
> From: <falcon@librelist.com> on behalf of Adriano Almeida
> Reply-To: "falcon@librelist.com"
> Date: Monday, August 3, 2015 at 2:45 PM
> To: "falcon@librelist.com"
> Subject: [falcon] Re: Error Handler
>
> Thanks Kurt. This answer it's working for a self raised error...
>
> But my problem it's when isn't a controled raised error...
>
> For example when the url it's not defined on falcon...
>
>
> El lunes, 3 de agosto de 2015, Kurt Griffiths <
> kurt.griffiths@rackspace.com> escribió:
>
>> Hi Adriano,
>>
>> The code linked below is based on your code sample, and should work. Is
>> this what you were trying to achieve? I’m happy to help in any way I can.
>>
>> https://gist.github.com/kgriffs/c9dabe86abad0bdf4791
>>
>>
>> -Kurt
>>
>
>
> --
> Adriano Almeida
>
>