Skip to content

Commit c096d7d

Browse files
Merge pull request #131 from otaviopace/refactor-errors-to-classes
errors: refactor to classes
2 parents 1dbc5e5 + 0330c6a commit c096d7d

File tree

10 files changed

+244
-127
lines changed

10 files changed

+244
-127
lines changed

.babelrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"presets": ["env"]
2+
"presets": ["env"],
3+
"plugins": [
4+
[
5+
"babel-plugin-transform-builtin-extend",
6+
{ globals: ["Error"] }
7+
]
8+
]
39
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Leia nosso guia de contribuição [aqui](CONTRIBUTING.md)
170170
| [<img src="https://avatars1.githubusercontent.com/u/8251208?v=3&s=115"><br><sub>@lucianopf</sub>](https://github.com/lucianopf) | [<img src="https://avatars1.githubusercontent.com/u/7863230?v=3&s=115"><br><sub>@MarcoWorms</sub>](https://github.com/MarcoWorms) | [<img src="https://avatars1.githubusercontent.com/u/551228?v=3&s=115"><br><sub>@caio-ribeiro-pereira</sub>](https://github.com/caio-ribeiro-pereira) | [<img src="https://avatars1.githubusercontent.com/u/1225447?v=3&s=115"><br><sub>@chrisbenseler</sub>](https://github.com/chrisbenseler) | [<img src="https://avatars0.githubusercontent.com/u/3428149?v=3&s=115"><br><sub>@luanmuniz</sub>](https://github.com/luanmuniz) | [<img src="https://avatars3.githubusercontent.com/u/3094496?v=3&s=115"><br><sub>@AlbertoTrindade</sub>](https://github.com/AlbertoTrindade) |
171171
|:-:|:-:|:-:|:-:|:-:|:-:|
172172
| [<img src="https://avatars1.githubusercontent.com/u/4137355?v=3&s=115"><br><sub>@pedrro</sub>](https://github.com/pedrro) | [<img src="https://avatars1.githubusercontent.com/u/8260778?v=3&s=115"><br><sub>@petronetto</sub>](https://github.com/Petronetto) | [<img src="https://avatars3.githubusercontent.com/u/434364?v=3&s=115"><br><sub>@olegon</sub>](https://github.com/olegon) | [<img src="https://avatars3.githubusercontent.com/u/2177742?v=3&s=115"><br><sub>@jhonnymoreira</sub>](https://github.com/jhonnymoreira) | [<img src="https://avatars3.githubusercontent.com/u/2955087?s=115&v=4"><br><sub>@claytonsilva</sub>](https://github.com/claytonsilva) | [<img src="https://avatars1.githubusercontent.com/u/13632762?s=115"><br><sub>@thiamsantos</sub>](https://github.com/thiamsantos) |
173-
| [<img src="https://avatars2.githubusercontent.com/u/6232791?v=3&s=115"><br><sub>@flyingluscas</sub>](https://github.com/flyingluscas) |
173+
| [<img src="https://avatars2.githubusercontent.com/u/6232791?v=3&s=115"><br><sub>@flyingluscas</sub>](https://github.com/flyingluscas) | [<img src="https://avatars1.githubusercontent.com/u/15306309?s=460&v=4"><br><sub>@otaviopace</sub>](https://github.com/otaviopace) |
174174

175175
## Autor
176176

dist/cep-promise-browser.js

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,74 @@
44
(global.cep = factory());
55
}(this, (function () { 'use strict';
66

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

13-
this.name = 'CepPromiseError';
14-
this.message = message;
15-
this.type = type;
16-
this.errors = errors;
17-
}
13+
var classCallCheck = function (instance, Constructor) {
14+
if (!(instance instanceof Constructor)) {
15+
throw new TypeError("Cannot call a class as a function");
16+
}
17+
};
18+
19+
var inherits = function (subClass, superClass) {
20+
if (typeof superClass !== "function" && superClass !== null) {
21+
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
22+
}
1823

19-
CepPromiseError.prototype = new Error();
24+
subClass.prototype = Object.create(superClass && superClass.prototype, {
25+
constructor: {
26+
value: subClass,
27+
enumerable: false,
28+
writable: true,
29+
configurable: true
30+
}
31+
});
32+
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
33+
};
34+
35+
var possibleConstructorReturn = function (self, call) {
36+
if (!self) {
37+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
38+
}
39+
40+
return call && (typeof call === "object" || typeof call === "function") ? call : self;
41+
};
42+
43+
var toConsumableArray = function (arr) {
44+
if (Array.isArray(arr)) {
45+
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
46+
47+
return arr2;
48+
} else {
49+
return Array.from(arr);
50+
}
51+
};
52+
53+
var CepPromiseError = function (_Error) {
54+
inherits(CepPromiseError, _Error);
55+
56+
function CepPromiseError() {
57+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
58+
message = _ref.message,
59+
type = _ref.type,
60+
errors = _ref.errors;
61+
62+
classCallCheck(this, CepPromiseError);
63+
64+
var _this = possibleConstructorReturn(this, (CepPromiseError.__proto__ || Object.getPrototypeOf(CepPromiseError)).call(this));
65+
66+
_this.name = 'CepPromiseError';
67+
_this.message = message;
68+
_this.type = type;
69+
_this.errors = errors;
70+
return _this;
71+
}
72+
73+
return CepPromiseError;
74+
}(Error);
2075

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

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

98-
function ServiceError() {
99-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
100-
message = _ref.message,
101-
service = _ref.service;
153+
var ServiceError = function (_Error) {
154+
inherits(ServiceError, _Error);
102155

103-
this.name = 'ServiceError';
104-
this.message = message;
105-
this.service = service;
106-
}
156+
function ServiceError() {
157+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
158+
message = _ref.message,
159+
service = _ref.service;
160+
161+
classCallCheck(this, ServiceError);
107162

108-
ServiceError.prototype = new Error();
163+
var _this = possibleConstructorReturn(this, (ServiceError.__proto__ || Object.getPrototypeOf(ServiceError)).call(this));
164+
165+
_this.name = 'ServiceError';
166+
_this.message = message;
167+
_this.service = service;
168+
return _this;
169+
}
170+
171+
return ServiceError;
172+
}(Error);
109173

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

308-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
309-
return typeof obj;
310-
} : function (obj) {
311-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
312-
};
313-
314-
var toConsumableArray = function (arr) {
315-
if (Array.isArray(arr)) {
316-
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
317-
318-
return arr2;
319-
} else {
320-
return Array.from(arr);
321-
}
322-
};
323-
324372
var reverse = function reverse(promise) {
325373
return new Promise(function (resolve, reject) {
326374
return Promise.resolve(promise).then(reject, resolve);

dist/cep-promise-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)