Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restify

Package Overview
Dependencies
Maintainers
0
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

lib/http_codes.js

12

lib/constants.js
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
module.exports = {
// Error codes
InvalidArgument: 'InvalidArgument',
InvalidCredentials: 'InvalidCredentials',
InvalidHeader: 'InvalidHeader',
MissingParameter: 'MissingParameter',
NotAuthorized: 'NotAuthorized',
RequestTooLarge: 'RequestTooLarge',
ResourceNotFound: 'ResourceNotFound',
UnknownError: 'UnknownError',
// Headers
XRequestId: 'X-RequestId',
XRequestId: 'X-Request-Id',
XApiVersion: 'X-API-Version',

@@ -17,0 +7,0 @@ XResponseTime: 'X-Response-Time',

// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
var Constants = require('./constants');
var HttpCodes = require('./http_codes');
var RestCodes = require('./rest_codes');

@@ -20,3 +22,3 @@ module.exports = {

e.name = Constants.HttpError;
e.httpCode = options.httpCode ? options.httpCode : 500;
e.httpCode = options.httpCode ? options.httpCode : HttpCodes.InternalError;
if (options.restCode) {

@@ -26,11 +28,11 @@ e.restCode = options.restCode;

switch (e.httpCode) {
case 404:
e.restCode = Constants.ResourceNotFound;
case HttpCodes.NotFound:
e.restCode = RestCodes.ResourceNotFound;
break;
case 400:
case 409:
e.restCode = Constants.InvalidArgument;
case HttpCodes.BadRequest:
case HttpCodes.Conflicy:
e.restCode = RestCodes.InvalidArgument;
break;
default:
e.restCode = Constants.UnknownError;
e.restCode = RestCodes.UnknownError;
}

@@ -37,0 +39,0 @@ }

@@ -12,2 +12,3 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

var Constants = require('./constants');
var HttpCodes = require('./http_codes');
var log = require('./log');

@@ -149,3 +150,3 @@

log.warn('Unknown error being returned: %s', error);
return this.send(500);
return this.send(HttpCodes.InternalError);
}

@@ -152,0 +153,0 @@

@@ -13,5 +13,8 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

var Constants = require('./constants');
var HttpCodes = require('./http_codes');
var RestCodes = require('./rest_codes');
var log = require('./log');
var newError = require('./error').newError;
var log = require('./log');
// Just force this to extend http.ServerResponse

@@ -27,3 +30,3 @@ require('./http-extra');

if (_response) {
_response.writeHead(500);
_response.writeHead(HttpCodes.InternalError);
_response.end();

@@ -113,4 +116,4 @@ _response = null;

return response.sendError(newError({
httpCode: 409,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.BadRequest,
restCode: RestCodes.InvalidArgument,
message: 'Accept header invalid: ' + request.headers.accept

@@ -122,4 +125,4 @@ }));

return response.sendError(newError({
httpCode: 409,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.BadRequest,
restCode: RestCodes.InvalidArgument,
message: 'Accept header invalid: ' + request.headers.accept

@@ -134,4 +137,4 @@ }));

return response.sendError(newError({
httpCode: 415,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.NotAcceptable,
restCode: RestCodes.InvalidArgument,
message: request.headers.accept + ' unsupported'

@@ -150,4 +153,4 @@ }));

return response.sendError(newError({
httpCode: 415,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.NotAcceptable,
restCode: RestCodes.InvalidArgument,
message: request.headers.accept + ' unsupported'

@@ -166,4 +169,4 @@ }));

return response.sendError(newError({
httpCode: 415,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.UnsupportedMediaType,
restCode: RestCodes.InvalidArgument,
message: 'multipart/form-data unsupported'

@@ -177,4 +180,4 @@ }));

return response.sendError(newError({
httpCode: 409,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.Conflict,
restCode: RestCodes.InvalidArgument,
message: Constants.XApiVersion + ' must be ' + request._apiVersion

@@ -200,4 +203,4 @@ }));

return response.sendError(newError({
httpCode: 413,
restCode: Constants.RequestTooLarge,
httpCode: HttpCodes.RequestTooLarge,
restCode: RestCodes.RequestTooLarge,
message: 'maximum HTTP data size is 8k'

@@ -215,4 +218,4 @@ }));

return response.sendError(newError({
httpCode: 409,
restCode: Constants.InvalidHeader,
httpCode: HttpCodes.BadRequest,
restCode: RestCodes.InvalidHeader,
message: 'Content-Length=' + contentLen +

@@ -231,4 +234,4 @@ ' didn\'t match actual length=' + request.body.length

return response.sendError(newError({
httpCode: 409,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.BadRequest,
restCode: RestCodes.InvalidArgument,
message: 'Invalid JSON: ' + e.message

@@ -239,4 +242,4 @@ }));

return response.sendError(newError({
httpCode: 415,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.UnsupportedMediaType,
restCode: RestCodes.InvalidArgument,
message: contentType + ' unsupported'

@@ -250,4 +253,4 @@ }));

return response.sendError(newError({
httpCode: 409,
restCode: Constants.InvalidArgument,
httpCode: HttpCodes.Conflict,
restCode: RestCodes.InvalidArgument,
message: 'duplicate parameter detected: ' + k

@@ -384,4 +387,6 @@ }));

log: log,
newError: newError
newError: newError,
HttpCodes: HttpCodes,
RestCodes: RestCodes
};
{
"name": "restify",
"description": "REST framework specifically meant for web service APIs",
"version": "0.1.0",
"version": "0.1.1",
"repository": {

@@ -6,0 +6,0 @@ "type": "git",

@@ -93,3 +93,3 @@ node-restify is meant to do one thing: make it easy to build an API webservice

* X-Api-Version // The version of the server api
* X-RequestId // a unique id for this request (uuid)
* X-Request-Id // a unique id for this request (uuid)
* X-Response-Time // Time taken (server side) in milliseconds

@@ -159,3 +159,3 @@ * Access-Control-Allow-Origin: *

X-API-Version: 2011-004-25
X-RequestId: C94A6FD8-9C37-405D-B66A-47E7B7D0F800
X-Request-Id: C94A6FD8-9C37-405D-B66A-47E7B7D0F800
X-Response-Time: 13

@@ -171,2 +171,5 @@ Content-Type: application/json

To leverage the built in error codes, pick up `restify.RestCodes`. Also, HTTP
constants are defined on `restify.HttpCodes`.
### Routes

@@ -230,2 +233,5 @@

* params: an object containing a merge of querystring, uri and body parameters.
* body: the raw body data that came in.
* startTime: the time the request was received at the server (not when data
was finished processing).

@@ -247,3 +253,3 @@ ### Response

response.send(newError({
httpCode: 404,
httpCode: HttpCodes.NotFound,
restCode: 'ClientParsableString',

@@ -250,0 +256,0 @@ message: 'Some string meant for a human'

@@ -14,3 +14,3 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

test.ok(response.headers['x-api-version']);
test.ok(response.headers['x-requestid']);
test.ok(response.headers['x-request-id']);
test.ok(response.headers['x-response-time']);

@@ -17,0 +17,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc