Criacao de uma mensagem para o erro

This commit is contained in:
joao_pedro 2025-10-23 06:34:25 -03:00
parent c6523f1b0d
commit 8878ad6ced
2 changed files with 11 additions and 13 deletions

View File

@ -5,6 +5,8 @@ import { useAuth } from "../AuthProvider";
function ModalErro ({showModal, setShowModal, ErrorData}) {
const {RefreshingToken} = useAuth()
const [modalMensagem, setModalMensagem] = useState("")
console.log("eerrroror", ErrorData)
useEffect(() => {
@ -12,8 +14,11 @@ if( ErrorData.httpStatus === 401){
setShowModal(false)
RefreshingToken()
console.log('uaua')
}
}, [])
}else if(ErrorData.httpStatus === 404){
setModalMensagem("Erro interno do sistema")
}else{setModalMensagem(ErrorData.mensagem)}
}, [ErrorData])
return(
@ -31,7 +36,7 @@ return(
<div className="modal-body">
{ErrorData.message}
{modalMensagem}
</div>

View File

@ -104,7 +104,6 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
};
useEffect(() => {
const authHeader = getAuthorizationHeader()
console.log(authHeader, 'aqui autorização')
@ -118,29 +117,23 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
redirect: 'follow'
};
fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients", requestOptions) // <-- Verifique se a URL está correta (patients)
fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/patients", requestOptions)
.then(response => {
// 1. VERIFICAÇÃO DO STATUS HTTP (Se não for 2xx)
if (!response.ok) {
// Lemos o corpo do erro JSON (PostgREST envia o JSON mesmo no 404/401)
return response.json().then(errorData => {
// 2. CRIAMOS O OBJETO DE ERRO CUSTOMIZADO COM TODOS OS DADOS NECESSÁRIOS
const errorObject = {
httpStatus: response.status, // 404, 401, 400, etc.
apiCode: errorData.code, // PGRST205, 42501, etc.
httpStatus: response.status,
apiCode: errorData.code,
message: errorData.message || response.statusText,
details: errorData.details,
hint: errorData.hint
};
// 3. LOG (para debug)
console.error("ERRO DETALHADO:", errorObject);
// 4. FORÇAMOS A FALHA DA PROMISE LANÇANDO O OBJETO CUSTOMIZADO
// NOTA: Ao lançar um objeto customizado, ele se torna o argumento 'error' no .catch
throw errorObject;
});
}