From 995271a8366f273a1b84e5d91a53806280a9d353 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 9 Jun 2018 18:18:50 +0200 Subject: [PATCH] refactor: usage of error utils --- src/lib/up-storage.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/up-storage.js b/src/lib/up-storage.js index 9cad3acff..576262f86 100644 --- a/src/lib/up-storage.js +++ b/src/lib/up-storage.js @@ -2,7 +2,6 @@ import zlib from 'zlib'; import JSONStream from 'JSONStream'; -import createError from 'http-errors'; import _ from 'lodash'; import request from 'request'; import Stream from 'stream'; @@ -114,7 +113,7 @@ class ProxyStorage implements IProxy { cb(ErrorCode.get500('uplink is offline')); } // $FlowFixMe - streamRead.emit('error', createError('uplink is offline')); + streamRead.emit('error', ErrorCode.get500('uplink is offline')); }); // $FlowFixMe streamRead._read = function() {}; @@ -415,7 +414,7 @@ class ProxyStorage implements IProxy { return callback( ErrorCode.get404('package doesn\'t exist on uplink')); } if (!(res.statusCode >= 200 && res.statusCode < 300)) { - const error = createError(500, `bad status code: ${res.statusCode}`); + const error = ErrorCode.get500(`bad status code: ${res.statusCode}`); // $FlowFixMe error.remoteStatus = res.statusCode; return callback(error); @@ -448,7 +447,7 @@ class ProxyStorage implements IProxy { return stream.emit('error', ErrorCode.get404('file doesn\'t exist on uplink')); } if (!(res.statusCode >= 200 && res.statusCode < 300)) { - return stream.emit('error', createError(500, 'bad uplink status code: ' + res.statusCode)); + return stream.emit('error', ErrorCode.get500(`bad uplink status code: ${res.statusCode}`)); } if (res.headers['content-length']) { expected_length = res.headers['content-length']; @@ -469,7 +468,7 @@ class ProxyStorage implements IProxy { current_length += data.length; } if (expected_length && current_length != expected_length) { - stream.emit('error', createError(500, 'content length mismatch')); + stream.emit('error', ErrorCode.get500('content length mismatch')); } }); return stream; @@ -498,7 +497,7 @@ class ProxyStorage implements IProxy { requestStream.on('response', (res) => { if (!String(res.statusCode).match(/^2\d\d$/)) { - return transformStream.emit('error', createError(500, `bad status code ${res.statusCode} from uplink`)); + return transformStream.emit('error', ErrorCode.get500(`bad status code ${res.statusCode} from uplink`)); } // See https://github.com/request/request#requestoptions-callback