Skip to content

Commit

Permalink
main: reduce Error functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hex7c0 committed Dec 21, 2016
1 parent 7b29688 commit 4fddb04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
43 changes: 17 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,6 @@ var end = new RegExp(/(.+)/g);
/*
* functions
*/
/**
* empty function
*
* @function end_empty
*/
function end_empty() {

return;
}

/**
* end with error. Propagate Error to callback
*
* @function end_err
* @param {next} next - continue routes
* @param {String} code - response error
* @return {Error}
*/
function end_err(next, code) {

var err = new Error(code);
return next ? next(err) : err;
}

/**
* end of work
*
Expand Down Expand Up @@ -227,9 +203,24 @@ function authentication(opt) {
}

// error handler
var err = end_err;
/**
* end with error. Propagate Error to callback
*
* @function end_err
* @param {next} next - continue routes
* @param {String} code - response error
* @return {Error}
*/
var err = function(next, code) {

var err = new Error(code);
return next ? next(err) : err;
};
if (my.suppress) {
err = end_empty;
err = function() {

return;
};
}

/**
Expand Down
14 changes: 5 additions & 9 deletions index.min.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
"use strict";

function end_empty() {}

function end_err(next, code) {
var err = new Error(code);
return next ? next(err) : err;
}

function end_work(err, next, code, res) {
if (void 0 === code) return !next || next();
var codes = http[code];
Expand Down Expand Up @@ -82,8 +75,11 @@ function authentication(opt) {
var user = String(options.user || "admin"), password = String(options.password || "password");
my.hash = new Buffer(user + ":" + password).toString("base64"), check = end_check;
}
var err = end_err;
return my.suppress && (err = end_empty), options.ending === !1 ? basic_medium : basic_big;
var err = function(next, code) {
var err = new Error(code);
return next ? next(err) : err;
};
return my.suppress && (err = function() {}), options.ending === !1 ? basic_medium : basic_big;
}

var http = require("http").STATUS_CODES, crypto = require("crypto").createHash, setHeader = require("setheaders").setWritableHeader, reg = new RegExp(/^Basic (.*)$/), basic = new RegExp(/^([^:]*):(.*)$/), end = new RegExp(/(.+)/g);
Expand Down

0 comments on commit 4fddb04

Please sign in to comment.