forked from RiseUP/riseup-squad23
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}) {
|
function ModalErro ({showModal, setShowModal, ErrorData}) {
|
||||||
const {RefreshingToken} = useAuth()
|
const {RefreshingToken} = useAuth()
|
||||||
|
|
||||||
|
const [modalMensagem, setModalMensagem] = useState("")
|
||||||
|
|
||||||
console.log("eerrroror", ErrorData)
|
console.log("eerrroror", ErrorData)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -12,8 +14,11 @@ if( ErrorData.httpStatus === 401){
|
|||||||
setShowModal(false)
|
setShowModal(false)
|
||||||
RefreshingToken()
|
RefreshingToken()
|
||||||
console.log('uaua')
|
console.log('uaua')
|
||||||
}
|
}else if(ErrorData.httpStatus === 404){
|
||||||
}, [])
|
setModalMensagem("Erro interno do sistema")
|
||||||
|
}else{setModalMensagem(ErrorData.mensagem)}
|
||||||
|
|
||||||
|
}, [ErrorData])
|
||||||
|
|
||||||
return(
|
return(
|
||||||
|
|
||||||
@ -31,7 +36,7 @@ return(
|
|||||||
|
|
||||||
<div className="modal-body">
|
<div className="modal-body">
|
||||||
|
|
||||||
{ErrorData.message}
|
{modalMensagem}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -104,7 +104,6 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
const authHeader = getAuthorizationHeader()
|
const authHeader = getAuthorizationHeader()
|
||||||
|
|
||||||
console.log(authHeader, 'aqui autorização')
|
console.log(authHeader, 'aqui autorização')
|
||||||
@ -118,29 +117,23 @@ function TablePaciente({ setCurrentPage, setPatientID }) {
|
|||||||
redirect: 'follow'
|
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 => {
|
.then(response => {
|
||||||
|
|
||||||
// 1. VERIFICAÇÃO DO STATUS HTTP (Se não for 2xx)
|
// 1. VERIFICAÇÃO DO STATUS HTTP (Se não for 2xx)
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
||||||
// Lemos o corpo do erro JSON (PostgREST envia o JSON mesmo no 404/401)
|
|
||||||
return response.json().then(errorData => {
|
return response.json().then(errorData => {
|
||||||
|
|
||||||
// 2. CRIAMOS O OBJETO DE ERRO CUSTOMIZADO COM TODOS OS DADOS NECESSÁRIOS
|
|
||||||
const errorObject = {
|
const errorObject = {
|
||||||
httpStatus: response.status, // 404, 401, 400, etc.
|
httpStatus: response.status,
|
||||||
apiCode: errorData.code, // PGRST205, 42501, etc.
|
apiCode: errorData.code,
|
||||||
message: errorData.message || response.statusText,
|
message: errorData.message || response.statusText,
|
||||||
details: errorData.details,
|
details: errorData.details,
|
||||||
hint: errorData.hint
|
hint: errorData.hint
|
||||||
};
|
};
|
||||||
|
|
||||||
// 3. LOG (para debug)
|
|
||||||
console.error("ERRO DETALHADO:", errorObject);
|
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;
|
throw errorObject;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user