Skip to content

Commit

Permalink
errors: refactor to classes
Browse files Browse the repository at this point in the history
  • Loading branch information
evaporei committed Dec 11, 2018
1 parent 1dbc5e5 commit 7b3e6ce
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 126 deletions.
8 changes: 7 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"presets": ["env"]
"presets": ["env"],
"plugins": [
[
"babel-plugin-transform-builtin-extend",
{ globals: ["Error"] }
]
]
}
120 changes: 84 additions & 36 deletions dist/cep-promise-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,74 @@
(global.cep = factory());
}(this, (function () { 'use strict';

function CepPromiseError() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
message = _ref.message,
type = _ref.type,
errors = _ref.errors;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};

this.name = 'CepPromiseError';
this.message = message;
this.type = type;
this.errors = errors;
}
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};

var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}

CepPromiseError.prototype = new Error();
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};

var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}

return call && (typeof call === "object" || typeof call === "function") ? call : self;
};

var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];

return arr2;
} else {
return Array.from(arr);
}
};

var CepPromiseError = function (_Error) {
inherits(CepPromiseError, _Error);

function CepPromiseError() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
message = _ref.message,
type = _ref.type,
errors = _ref.errors;

classCallCheck(this, CepPromiseError);

var _this = possibleConstructorReturn(this, (CepPromiseError.__proto__ || Object.getPrototypeOf(CepPromiseError)).call(this));

_this.name = 'CepPromiseError';
_this.message = message;
_this.type = type;
_this.errors = errors;
return _this;
}

return CepPromiseError;
}(Error);

var index = typeof fetch == 'function' ? fetch.bind() : function (url, options) {
options = options || {};
Expand Down Expand Up @@ -95,17 +150,26 @@ var require$$0 = ( unfetch_es && index ) || unfetch_es;

var browser = window.fetch || (window.fetch = require$$0.default || require$$0);

function ServiceError() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
message = _ref.message,
service = _ref.service;
var ServiceError = function (_Error) {
inherits(ServiceError, _Error);

this.name = 'ServiceError';
this.message = message;
this.service = service;
}
function ServiceError() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
message = _ref.message,
service = _ref.service;

classCallCheck(this, ServiceError);

ServiceError.prototype = new Error();
var _this = possibleConstructorReturn(this, (ServiceError.__proto__ || Object.getPrototypeOf(ServiceError)).call(this));

_this.name = 'ServiceError';
_this.message = message;
_this.service = service;
return _this;
}

return ServiceError;
}(Error);

var PROXY_URL = 'https://proxier.now.sh/';
var CEP_ABERTO_TOKEN = '37d718d2984e6452584a76d3d59d3a26';
Expand Down Expand Up @@ -305,22 +369,6 @@ var CepAbertoService = typeof process === 'undefined' ? injectProxy(fetchCepAber
var CorreiosService = typeof process === 'undefined' ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
var ViaCepService = fetchViaCepService;

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};

var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];

return arr2;
} else {
return Array.from(arr);
}
};

var reverse = function reverse(promise) {
return new Promise(function (resolve, reject) {
return Promise.resolve(promise).then(reject, resolve);
Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise-browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7b3e6ce

Please sign in to comment.