chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] How to catch an error when http-client can't connect


From: Peter Bex
Subject: Re: [Chicken-users] How to catch an error when http-client can't connect?
Date: Wed, 23 Jul 2014 22:34:08 +0200
User-agent: Mutt/1.4.2.3i

On Wed, Jul 23, 2014 at 10:10:05PM +0200, Christian Kellermann wrote:
> Matt Welland <address@hidden> writes:
> 
> > I'd like to handle the case where http-client gets denied a
> > connection. I wrapped the call to with-input-from-request with a
> > handle-exceptions but that doesn't catch the error.
> 
> How do you try to catch it?
> 
> The following seems to work for me in csi:
> 
> #;1> (thread-start!
>  (make-thread
>    (lambda ()
>      (with-exception-handler (lambda (e) (print e))
>                              (lambda ()
>                                (with-input-from-request
>                                   "http://localhost";
>                                    #f read-lines))))))
> 
> #<thread: thread227>
> #;2> #<condition: (exn http server-error)>
> 
> The warning is an indication that the exception does not get caught in a
> thread handler but the primordeal thread, see also the notes in
> http://api.call-cc.org/doc/srfi-18#sec:Notes

It's better to catch specifically the exception for the situation
you want to handle, so that unexpected errors won't get caught
by accident.  Condition-case is your friend in that case:

(condition-case (with-input-from-request "http://localhost"; #f read-lines)
  ((exn http client-error) e (print e)))

By doing this, any server-side error will get cause an exception to
propagate outward, whereas client-side errors (403 permission denied,
404 not found etc) will get caught and printed.

>From your output, it seems there's a server-error BTW, so maybe
something's going wrong at the other end?

Cheers,
Peter
-- 
http://www.more-magic.net



reply via email to

[Prev in Thread] Current Thread [Next in Thread]