21 lines
756 B
JavaScript
21 lines
756 B
JavaScript
import cFetch from "cross-fetch";
|
|
import { respostaComuns } from "p-respostas";
|
|
export const tx_listar_prefeituras = "listar_prefeituras";
|
|
export const listarPrefeituras = async ({ url_api_autenticacao, }) => {
|
|
const url = `${url_api_autenticacao}/api/${tx_listar_prefeituras}`;
|
|
return cFetch(url)
|
|
.then(async (a) => {
|
|
const texto = await a.text();
|
|
try {
|
|
const res = JSON.parse(texto);
|
|
return res;
|
|
}
|
|
catch (error) {
|
|
return respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
|
texto,
|
|
error,
|
|
]);
|
|
}
|
|
})
|
|
.catch((error) => respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [error]));
|
|
};
|