New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apis-endpoint

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apis-endpoint - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

67

index.js

@@ -6,2 +6,3 @@ var express = require('express');

var _ = require('lodash');
var domain = require('domain');

@@ -56,31 +57,47 @@ module.exports = Endpoint;

if(cb.length === 3){
//A function has been promisified
callback = cb();
}else if(typeof cb === 'object'){
//It is just a new Promise, should not be like that though
//it always returns the same response
callback = cb;
}else if(cb.length === 2){
//It is a standard callback
callback = Promise.promisify(cb)(obj);
}else{
//It is already a promise
callback = cb(obj);
}
//If the endpoint does something terribly wrong it crashes the whole app.
//Therefore we need a good strategy to solve it.
//For now lets use error domains
var d = domain.create();
callback
.then(function(data) {
res.json(data);
})
.catch(function(err) {
console.error(err.stack);
d.on('error', function(err) {
console.error(err.stack);
var code = parseInt(err.message);
res.status(500).json({
error: statuses[500]
});
});
err = !isNaN(parseFloat(code)) && isFinite(code) ? code : 500;
res.status(err).json({
error: statuses[err]
d.run(function() {
if(cb.length === 3){
//A function has been promisified
callback = cb();
}else if(typeof cb === 'object'){
//It is just a new Promise, should not be like that though
//it always returns the same response
callback = cb;
}else if(cb.length === 2){
//It is a standard callback
callback = Promise.promisify(cb)(obj);
}else{
//It is already a promise
callback = cb(obj);
}
callback
.then(function(data) {
res.json(data);
})
.catch(function(err) {
console.error(err.stack);
var code = parseInt(err.message);
err = !isNaN(parseFloat(code)) && isFinite(code) ? code : 500;
res.status(err).json({
error: statuses[err]
});
});
});
});
});

@@ -87,0 +104,0 @@ };

{
"name": "apis-endpoint",
"version": "0.2.0",
"version": "0.2.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

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