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

cass

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cass - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

37

index.js

@@ -5,4 +5,2 @@ 'use strict';

const WebError = require('./web-error');
function ptry(f, self, args) {

@@ -14,10 +12,10 @@ return new Promise(function(resolve) {

function makeDefaultErrorHandler(serialize) {
function defaultErrorHandler(req, error) {
function createErrorHandler(serialize) {
function errorHandler(req, error) {
let message = 'Something went wrong',
statusCode = 500;
if (error instanceof WebError) {
if (error.name === 'HTTPError' || error.name === 'WebError') {
message = error.message;
statusCode = error.statusCode;
statusCode = error.statusCode || error.status || 500;
}

@@ -30,11 +28,12 @@

return defaultErrorHandler;
return errorHandler;
}
const defaultErrorHandler = makeDefaultErrorHandler(json);
function cass(options) {
function cass(options, inner) {
if (inner === undefined) {
inner = options, options = {};
}
options = options || {};
const serialize = options.serialize || json;
const errorHandler = options.errorHandler || makeDefaultErrorHandler(serialize);
const errorHandler = options.errorHandler || createErrorHandler(serialize);

@@ -46,11 +45,9 @@ function resolveResponse(res) {

function withHandler(inner) {
return function (req) {
return ptry(inner, this, arguments)
.then(resolveResponse)
.catch(errorHandler.bind(null, req));
};
function handler(req) {
return ptry(inner, this, arguments)
.then(resolveResponse)
.catch(errorHandler.bind(null, req));
}
return withHandler;
return handler;
}

@@ -60,4 +57,2 @@

cass['default'] = cass;
cass['defaultErrorHandler'] = defaultErrorHandler;
cass['makeDefaultErrorHandler'] = makeDefaultErrorHandler;
cass['WebError'] = WebError;
cass['createErrorHandler'] = createErrorHandler;
{
"name": "cass",
"version": "0.0.2",
"version": "0.0.3",
"description": "It rhymes with jax-rs",

@@ -18,3 +18,3 @@ "main": "index.js",

"concat-stream": "^1.4.8",
"quinn": "^3.2.0",
"node-http-error": "^0.2.0",
"tape": "^4.0.0"

@@ -21,0 +21,0 @@ },

@@ -5,10 +5,12 @@ # Cass

A convenience layer to build JSON APIs using [`Quinn`](https://github.com/quinnjs/quinn).
A convenience layer to build JSON APIs using
[`Quinn`](https://github.com/quinnjs/quinn).
```js
const cass = require('cass'),
WebError = cass.WebError;
// HTTPError is whitelisted for providing status codes
HTTPError = require('node-http-error');
const handler = cass()(req => {
if (req.method !== 'GET') throw new WebError(405);
const handler = cass(req => {
if (req.method !== 'GET') throw new HTTPError(405);

@@ -55,4 +57,4 @@ return {

// node style request listener -> node http server
createServer(createApp(cass()(createRouter(routes))))
createServer(createApp(cass(createRouter(routes))))
.listen(3000);
```

@@ -5,5 +5,5 @@ 'use strict';

const respond = require('quinn/respond');
const HTTPError = require('node-http-error');
const cass = require('../'),
WebError = cass.WebError;
const cass = require('../');

@@ -28,3 +28,3 @@ const testQuinnHandler = require('./test-quinn-handler');

testQuinnHandler(cass()(throwError))
testQuinnHandler(cass(throwError))
.then(verify, t.end);

@@ -37,3 +37,3 @@ });

function throwError() {
throw new WebError('Invalid thing', 422);
throw new HTTPError(422, 'Invalid thing');
}

@@ -50,3 +50,3 @@

testQuinnHandler(cass()(throwError))
testQuinnHandler(cass(throwError))
.then(verify, t.end);

@@ -77,4 +77,4 @@ });

const req = { url: '/foo', method: 'GET' };
testQuinnHandler(cass({ errorHandler: customErrorHandler })(throwError), req)
testQuinnHandler(cass({ errorHandler: customErrorHandler }, throwError), req)
.then(verify, t.end);
});

@@ -23,4 +23,4 @@ 'use strict';

testQuinnHandler(cass()(renderHelloWorld))
testQuinnHandler(cass(renderHelloWorld))
.then(verify, t.end);
});
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