1
0
Fork 0

Allow passing strings as status code in some cases

This commit is contained in:
Alan Plum 2016-04-13 15:23:11 +02:00
parent e22e656f5d
commit 30d6200a60
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
2 changed files with 9 additions and 0 deletions

View File

@ -194,6 +194,9 @@ module.exports = class SyntheticResponse {
}
sendStatus(status) {
if (typeof status === 'string') {
status = statuses(status);
}
const message = String(statuses[status] || status);
this.statusCode = status;
this.body = message;
@ -212,6 +215,9 @@ module.exports = class SyntheticResponse {
}
status(statusCode) {
if (typeof statusCode === 'string') {
statusCode = statuses(statusCode);
}
this.statusCode = statusCode;
return this;
}

View File

@ -262,6 +262,9 @@ module.exports = exports = class SwaggerContext {
}
error(status, reason) {
if (typeof status === 'string') {
status = statuses(status);
}
return this.response(
status,
DEFAULT_ERROR_SCHEMA,