Created
February 3, 2015 19:57
-
-
Save kwhitaker/e80296dd6016cf2a8df6 to your computer and use it in GitHub Desktop.
Decorator plugin for superagent.js, which lets you take actions on a response before the callback is fired.
This file contains 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
# Use superagent's standard plugin architecture: | |
# superagent.get('/some/url').use(agentInterceptor).end(function(res){...}); | |
agentInterceptor = (res) -> | |
Request = superagent.Request | |
oldCb = Request.prototype.callback | |
Request.prototype.callback = (err, r) -> | |
switch r.status | |
when 404 | |
some404Func() | |
when 500 | |
someErrorFunc() | |
else | |
oldCb.apply @, [err, r] | |
module.exports = agentInterceptor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment