Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

util-superagent-serializer

benpptung16MIT1.0.2

process superagent response to get better error logging result

superagent

readme

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; }