Criacao de uma mensagem para o erro
This commit is contained in:
parent
c6523f1b0d
commit
8878ad6ced
@ -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>
|
||||
|
||||
|
||||
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user