Skip to content

Instantly share code, notes, and snippets.

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