diff --git a/README.md b/README.md index 0c91671..e72fcd3 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,11 @@ response error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR) }); -response.status(HttpStatus.getStatusCode('No Content')) - .send(); +response + .status(HttpStatus.getStatusCode('Server Error')) + .send({ + error: 'Server Error' + }); ``` ## Codes @@ -112,8 +115,10 @@ response }) response - .status(getStatusCode('No Content') - .send() + .status(HttpStatus.getStatusCode('Server Error')) + .send({ + error: 'Server Error' + }) ``` Option 2: Selective import @@ -126,6 +131,6 @@ response .send(getStatusText(OK)) response - .status(getStatusCode('No Content') - .send() + .status(getStatusCode('Server Error') + .send('Server Error') ``` diff --git a/index.d.ts b/index.d.ts index 9ddfbfa..46f98ad 100644 --- a/index.d.ts +++ b/index.d.ts @@ -389,8 +389,9 @@ export declare enum HTTP_STATUS { export declare function getStatusText(statusCode: number): string; /** - * Convert the status code title to its appropriate numeric value - * @param statusText One of the available status texts in this package - * @returns {Number} The associated status code of the passed status text - * @throws {Error} The status text does not exist -export declare function getStatusCode(statusText: string): number; + * Convert the status reason phrase to its appropriate numeric value + * @param statusText One of the available reason phrases in this package + * @returns {Number} The associated status code of the passed reason phrase + * @throws {Error} The reason phrase does not exist + */ +export declare function getStatusCode(reasonPhrase: string): number; diff --git a/index.js b/index.js index 691ac52..fe15eaa 100644 --- a/index.js +++ b/index.js @@ -75,12 +75,12 @@ exports.getStatusText = function(statusCode) { } }; -exports.getStatusCode = function(statusText) { +exports.getStatusCode = function(reasonPhrase) { for (key in statusCodes) { - if (statusCodes[key] === statusText) { + if (statusCodes[key] === reasonPhrase) { return parseInt(key, 10); } } - throw new Error("Status text does not exist: " + statusText); + throw new Error("Reason phrase does not exist: " + reasonPhrase); };