Created
March 18, 2015 12:26
-
-
Save JasonHewison/19266e91a4e51d24b00d to your computer and use it in GitHub Desktop.
Examples of how you could use DeferredHTTPStatuses in a more ES6 Promise style way
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
reject.badRequest(new Error('The request was bad.')); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
reject.conflict(); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
reject.forbidden(); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
reject.gone(); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
reject.internalServerError(); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
resolve.noContent(); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
reject.notFound(); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
reject.withStatus(500, new Error('This is an internal server error')); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
var result = {}; | |
resolve.withStatus(200, result); | |
}); |
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
var deferred = require('deferred-http-statuses'); | |
return deferred(function (resolve, reject) { | |
var result = {}; | |
resolve.success(result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment