Comparing version 0.0.2 to 0.1.0
@@ -91,39 +91,44 @@ // Load modules | ||
internals.Error.unauthorized = function (message, scheme, attributes) { | ||
internals.Error.unauthorized = function (error, scheme, attributes) { | ||
var err = new internals.Error(401, message); | ||
var err = new internals.Error(401, error); | ||
if (scheme) { | ||
var wwwAuthenticate = scheme; | ||
if (attributes) { | ||
var names = Object.keys(attributes); | ||
for (var i = 0, il = names.length; i < il; ++i) { | ||
if (i) { | ||
wwwAuthenticate += ','; | ||
} | ||
if (!scheme) { | ||
return err; | ||
} | ||
var value = attributes[names[i]]; | ||
if (value === null || | ||
value === undefined) { // Value can be zero | ||
var wwwAuthenticate = scheme; | ||
if (attributes) { | ||
var names = Object.keys(attributes); | ||
for (var i = 0, il = names.length; i < il; ++i) { | ||
if (i) { | ||
wwwAuthenticate += ','; | ||
} | ||
value = ''; | ||
} | ||
wwwAuthenticate += ' ' + names[i] + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
var value = attributes[names[i]]; | ||
if (value === null || | ||
value === undefined) { // Value can be zero | ||
value = ''; | ||
} | ||
wwwAuthenticate += ' ' + names[i] + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
} | ||
} | ||
if (message) { | ||
if (attributes) { | ||
wwwAuthenticate += ','; | ||
} | ||
wwwAuthenticate += ' error="' + Hoek.escapeHeaderAttribute(message) + '"'; | ||
if (error) { | ||
if (attributes) { | ||
wwwAuthenticate += ','; | ||
} | ||
wwwAuthenticate += ' error="' + Hoek.escapeHeaderAttribute(error) + '"'; | ||
} | ||
else { | ||
err.isMissing = true; | ||
} | ||
err.toResponse = function () { | ||
err.toResponse = function () { | ||
var response = internals.toResponse.call(this); | ||
response.headers = { 'WWW-Authenticate': wwwAuthenticate }; | ||
return response; | ||
}; | ||
} | ||
var response = internals.toResponse.call(this); | ||
response.headers = { 'WWW-Authenticate': wwwAuthenticate }; | ||
return response; | ||
}; | ||
@@ -130,0 +135,0 @@ return err; |
{ | ||
"name": "boom", | ||
"description": "HTTP-friendly error objects", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors": [], |
@@ -87,2 +87,16 @@ // Load modules | ||
}); | ||
it('sets the isMissing flag when error message is empty', function (done) { | ||
var err = Boom.unauthorized('', 'Basic'); | ||
expect(err.isMissing).to.equal(true); | ||
done(); | ||
}); | ||
it('does not set the isMissing flag when error message is not empty', function (done) { | ||
var err = Boom.unauthorized('message', 'Basic'); | ||
expect(err.isMissing).to.equal(undefined); | ||
done(); | ||
}); | ||
}); | ||
@@ -89,0 +103,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14187
280