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

util-superagent-serializer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

util-superagent-serializer

process superagent response to get better error logging result

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

process superagent response to get better error logging result

Example

const request = require('superagent');
const serial = require('util-superagent-serializer');

superagent.get(restful_url)
  .end((err, res)=>{
    
    // superagent will detect general http level error for you(404, 403, 500...)
    if (err) return console.error(err);
    
    // Golden Rule: in javascript, you should trust your own input
    // But, you should NEVER trust 3rd party input. `res` is 3rd party input
    
    if (!isSomething(res)) return console.error(NotSomethingErr(res));
    
    // Now, you can trust the res, and continue your codes
    ....
  });
  

function isSomething(res) {
  // check if the res is something you want here
}

function NotSomethingErr(res) {
  
  var err = new TypeError('we got something unknown');
  
  // serialize the res, and log the error, so we know what happened.
  err.original = serial(res);
  return err;
}

Keywords

FAQs

Package last updated on 13 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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