Skip to content

Commit 08a911d

Browse files
Fix correios alt
1 parent 5e40de4 commit 08a911d

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

dist/cep-promise-browser.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390
}
391391
function parseResponse(response) {
392392
return response.json().then(function (result) {
393-
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
393+
if (result.total === 0 || result.erro || result.dados[0].cep === "" || result.dados[0].cep.replace(/\D/g, '') !== cepWithLeftPad) {
394394
throw new Error('CEP não encontrado na base dos Correios.');
395395
}
396396
return result;
@@ -466,14 +466,13 @@
466466
throw serviceError;
467467
}
468468

469-
function fetchWideNetService(cepWithLeftPad, configurations) {
470-
var cepWithDash = "".concat(cepWithLeftPad.slice(0, 5), "-").concat(cepWithLeftPad.slice(5));
471-
var url = "https://cdn.apicep.com/file/apicep/".concat(cepWithDash, ".json");
469+
function fetchViaCepService$1(cepWithLeftPad, configurations) {
470+
var url = "https://api.postmon.com.br/v1/cep/".concat(cepWithLeftPad);
472471
var options = {
473472
method: 'GET',
474473
mode: 'cors',
475474
headers: {
476-
accept: 'application/json'
475+
'content-type': 'application/json;charset=utf-8'
477476
},
478477
timeout: configurations.timeout || 30000
479478
};

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.

dist/cep-promise.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
}
346346
function parseResponse(response) {
347347
return response.json().then(function (result) {
348-
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
348+
if (result.total === 0 || result.erro || result.dados[0].cep === "" || result.dados[0].cep.replace(/\D/g, '') !== cepWithLeftPad) {
349349
throw new Error('CEP não encontrado na base dos Correios.');
350350
}
351351
return result;
@@ -421,14 +421,13 @@
421421
throw serviceError;
422422
}
423423

424-
function fetchWideNetService(cepWithLeftPad, configurations) {
425-
var cepWithDash = "".concat(cepWithLeftPad.slice(0, 5), "-").concat(cepWithLeftPad.slice(5));
426-
var url = "https://cdn.apicep.com/file/apicep/".concat(cepWithDash, ".json");
424+
function fetchViaCepService$1(cepWithLeftPad, configurations) {
425+
var url = "https://api.postmon.com.br/v1/cep/".concat(cepWithLeftPad);
427426
var options = {
428427
method: 'GET',
429428
mode: 'cors',
430429
headers: {
431-
accept: 'application/json'
430+
'content-type': 'application/json;charset=utf-8'
432431
},
433432
timeout: configurations.timeout || 30000
434433
};

dist/cep-promise.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.

src/services/correios-alt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function fetchCorreiosAltAPIService(
2828

2929
function parseResponse(response) {
3030
return response.json().then(result => {
31-
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
31+
if (result.total === 0 || result.erro || result.dados[0].cep === "" || result.dados[0].cep.replace(/\D/g, '') !== cepWithLeftPad) {
3232
throw new Error('CEP não encontrado na base dos Correios.')
3333
}
3434
return result

src/services/postmon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function analyzeAndParseResponse (response) {
3434
}
3535

3636
function checkForPostmanError (responseObject) {
37-
if (!responseObject) {
37+
if (!responseObject ) {
3838
throw new Error('CEP não encontrado na base do Postmon.')
3939
}
4040

0 commit comments

Comments
 (0)