diff --git a/dist-import/pilao-de-dados/Pilao/index.js b/dist-import/pilao-de-dados/Pilao/index.js index de60469..38c14d6 100644 --- a/dist-import/pilao-de-dados/Pilao/index.js +++ b/dist-import/pilao-de-dados/Pilao/index.js @@ -53,7 +53,14 @@ class ClassPilao { method: "POST", headers: { "Content-Type": "application/json" }, }); - return await response.json(); + const texto = await response.text(); + try { + const json = JSON.parse(texto); + return json; + } + catch { + return respostaComuns.erro("Consulta não retornou json válido", [texto]); + } } catch (erro) { console.error(erro); @@ -106,13 +113,14 @@ class ClassPilao { headers: { "Content-Type": "application/json" }, }) .then(async (r) => { + const texto = await r.text(); try { - return await r.json(); + const json = JSON.parse(texto); + return json; } catch { return respostaComuns.erro("Consulta não retornou json válido", [ - await r.text(), - r.statusText, + texto, ]); } }) @@ -139,7 +147,18 @@ class ClassPilao { body: JSON.stringify(parametros), headers: { "Content-Type": "application/json" }, }) - .then((r) => r.json()) + .then(async (r) => { + const texto = await r.text(); + try { + const json = JSON.parse(texto); + return json; + } + catch { + return respostaComuns.erro("Consulta não retornou json válido", [ + texto, + ]); + } + }) .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message])); if (__classPrivateFieldGet(this, _ClassPilao_ver_log, "f")) console.log(`[PILÃO]: buscar dados de "${JSON.stringify(parametros)}" para "${url}".`); diff --git a/dist-require/pilao-de-dados/Pilao/index.js b/dist-require/pilao-de-dados/Pilao/index.js index 00ea63c..9bad062 100644 --- a/dist-require/pilao-de-dados/Pilao/index.js +++ b/dist-require/pilao-de-dados/Pilao/index.js @@ -59,7 +59,14 @@ class ClassPilao { method: "POST", headers: { "Content-Type": "application/json" }, }); - return await response.json(); + const texto = await response.text(); + try { + const json = JSON.parse(texto); + return json; + } + catch { + return p_respostas_1.respostaComuns.erro("Consulta não retornou json válido", [texto]); + } } catch (erro) { console.error(erro); @@ -112,13 +119,14 @@ class ClassPilao { headers: { "Content-Type": "application/json" }, }) .then(async (r) => { + const texto = await r.text(); try { - return await r.json(); + const json = JSON.parse(texto); + return json; } catch { return p_respostas_1.respostaComuns.erro("Consulta não retornou json válido", [ - await r.text(), - r.statusText, + texto, ]); } }) @@ -145,7 +153,18 @@ class ClassPilao { body: JSON.stringify(parametros), headers: { "Content-Type": "application/json" }, }) - .then((r) => r.json()) + .then(async (r) => { + const texto = await r.text(); + try { + const json = JSON.parse(texto); + return json; + } + catch { + return p_respostas_1.respostaComuns.erro("Consulta não retornou json válido", [ + texto, + ]); + } + }) .catch((e) => p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message])); if (__classPrivateFieldGet(this, _ClassPilao_ver_log, "f")) console.log(`[PILÃO]: buscar dados de "${JSON.stringify(parametros)}" para "${url}".`); diff --git a/package.json b/package.json index 64800e3..7e7f301 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p-drives", - "version": "0.170.0", + "version": "0.171.0", "description": "", "main": "src/index.ts", "exports": { diff --git a/src/pilao-de-dados/Pilao/index.ts b/src/pilao-de-dados/Pilao/index.ts index 3776298..ba075b6 100644 --- a/src/pilao-de-dados/Pilao/index.ts +++ b/src/pilao-de-dados/Pilao/index.ts @@ -78,7 +78,15 @@ class ClassPilao { method: "POST", headers: { "Content-Type": "application/json" }, }) - return await response.json() + + const texto = await response.text() + + try { + const json = JSON.parse(texto) + return json + } catch { + return respostaComuns.erro("Consulta não retornou json válido", [texto]) + } } catch (erro) { console.error(erro) return respostaComuns.erroInterno({ @@ -149,12 +157,13 @@ class ClassPilao { headers: { "Content-Type": "application/json" }, }) .then(async (r) => { + const texto = await r.text() try { - return await r.json() + const json = JSON.parse(texto) + return json } catch { return respostaComuns.erro("Consulta não retornou json válido", [ - await r.text(), - r.statusText, + texto, ]) } }) @@ -223,7 +232,18 @@ class ClassPilao { body: JSON.stringify(parametros), headers: { "Content-Type": "application/json" }, }) - .then((r) => r.json()) + .then(async (r) => { + const texto = await r.text() + + try { + const json = JSON.parse(texto) + return json + } catch { + return respostaComuns.erro("Consulta não retornou json válido", [ + texto, + ]) + } + }) .catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]), )