Skip to content

Commit

Permalink
Fix correios alt
Browse files Browse the repository at this point in the history
  • Loading branch information
RodriAndreotti committed Feb 22, 2024
1 parent 5e40de4 commit 08a911d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
9 changes: 4 additions & 5 deletions dist/cep-promise-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
}
function parseResponse(response) {
return response.json().then(function (result) {
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
if (result.total === 0 || result.erro || result.dados[0].cep === "" || result.dados[0].cep.replace(/\D/g, '') !== cepWithLeftPad) {
throw new Error('CEP não encontrado na base dos Correios.');
}
return result;
Expand Down Expand Up @@ -466,14 +466,13 @@
throw serviceError;
}

function fetchWideNetService(cepWithLeftPad, configurations) {
var cepWithDash = "".concat(cepWithLeftPad.slice(0, 5), "-").concat(cepWithLeftPad.slice(5));
var url = "https://cdn.apicep.com/file/apicep/".concat(cepWithDash, ".json");
function fetchViaCepService$1(cepWithLeftPad, configurations) {
var url = "https://api.postmon.com.br/v1/cep/".concat(cepWithLeftPad);
var options = {
method: 'GET',
mode: 'cors',
headers: {
accept: 'application/json'
'content-type': 'application/json;charset=utf-8'
},
timeout: configurations.timeout || 30000
};
Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise-browser.min.js

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions dist/cep-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
}
function parseResponse(response) {
return response.json().then(function (result) {
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
if (result.total === 0 || result.erro || result.dados[0].cep === "" || result.dados[0].cep.replace(/\D/g, '') !== cepWithLeftPad) {
throw new Error('CEP não encontrado na base dos Correios.');
}
return result;
Expand Down Expand Up @@ -421,14 +421,13 @@
throw serviceError;
}

function fetchWideNetService(cepWithLeftPad, configurations) {
var cepWithDash = "".concat(cepWithLeftPad.slice(0, 5), "-").concat(cepWithLeftPad.slice(5));
var url = "https://cdn.apicep.com/file/apicep/".concat(cepWithDash, ".json");
function fetchViaCepService$1(cepWithLeftPad, configurations) {
var url = "https://api.postmon.com.br/v1/cep/".concat(cepWithLeftPad);
var options = {
method: 'GET',
mode: 'cors',
headers: {
accept: 'application/json'
'content-type': 'application/json;charset=utf-8'
},
timeout: configurations.timeout || 30000
};
Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/services/correios-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function fetchCorreiosAltAPIService(

function parseResponse(response) {
return response.json().then(result => {
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
if (result.total === 0 || result.erro || result.dados[0].cep === "" || result.dados[0].cep.replace(/\D/g, '') !== cepWithLeftPad) {
throw new Error('CEP não encontrado na base dos Correios.')
}
return result
Expand Down
2 changes: 1 addition & 1 deletion src/services/postmon.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function analyzeAndParseResponse (response) {
}

function checkForPostmanError (responseObject) {
if (!responseObject) {
if (!responseObject ) {
throw new Error('CEP não encontrado na base do Postmon.')
}

Expand Down

0 comments on commit 08a911d

Please sign in to comment.