Created
September 6, 2011 02:21
-
-
Save seanmonstar/1196406 to your computer and use it in GitHub Desktop.
Coffee exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| req = (request, errorOnTimeout) -> | |
| try | |
| request.send | |
| catch InvalidHeaderError, e | |
| console.error 'wrong headers' | |
| catch TimeoutError, e | |
| if errorOnTimeout | |
| console.error 'timed out!' | |
| else | |
| console.log 'timed out, trying once more' | |
| req(request, true) | |
| catch Error, e | |
| console.log 'some other error' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function request(request, errorOnTimeout) { | |
| try { | |
| request.send(); | |
| } catch (error) { | |
| if (error instanceof InvalidHeaderError) { | |
| var e = error; | |
| console.error('wrong headers'); | |
| } else if (error instanceof TimeoutError) { | |
| var e = error; | |
| if (errorOnTimeout) { | |
| console.error('timed out!'); | |
| } else { | |
| console.log('timed out, trying again'); | |
| req(request, true); | |
| } | |
| } else if (error instanceof Error) { | |
| var e = error; | |
| console.log('some other error'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment