diff --git a/src/components/utils/fetchErros/ModalErro.jsx b/src/components/utils/fetchErros/ModalErro.jsx index 92663ab..c1d1912 100644 --- a/src/components/utils/fetchErros/ModalErro.jsx +++ b/src/components/utils/fetchErros/ModalErro.jsx @@ -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(
- {ErrorData.message} + {modalMensagem}
diff --git a/src/pages/TablePaciente.jsx b/src/pages/TablePaciente.jsx index 6d269f1..bdcbff0 100644 --- a/src/pages/TablePaciente.jsx +++ b/src/pages/TablePaciente.jsx @@ -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; }); }