(err, res, cb)
| 425 | |
| 426 | |
| 427 | function readError(err, res, cb) { |
| 428 | assert.object(err); |
| 429 | assert.optionalObject(res); |
| 430 | assert.func(cb); |
| 431 | |
| 432 | if (res === null) |
| 433 | return (cb(null, err, res)); |
| 434 | |
| 435 | var body = ''; |
| 436 | res.setEncoding('utf8'); |
| 437 | res.on('data', function (chunk) { |
| 438 | body += chunk; |
| 439 | }); |
| 440 | |
| 441 | res.once('end', function () { |
| 442 | err._body = body; |
| 443 | |
| 444 | try { |
| 445 | err.body = JSON.parse(body); |
| 446 | } catch (e) { |
| 447 | } |
| 448 | |
| 449 | err.body = err.body || {}; |
| 450 | err.code = err.body.code; |
| 451 | err.message = err.body.message; |
| 452 | err.name = err.body.code || err.name; |
| 453 | if (!/.*Error$/.test(err.name)) |
| 454 | err.name += 'Error'; |
| 455 | |
| 456 | cb(null, err, res); |
| 457 | }); |
| 458 | |
| 459 | return (undefined); |
| 460 | } |
| 461 | |
| 462 | |
| 463 | function resultToInfoCb(_path, cb) { |
no test coverage detected