add axios
This commit is contained in:
@@ -1,5 +1,25 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export default axios.create({
|
||||
const instance = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_URL,
|
||||
})
|
||||
|
||||
instance.interceptors.response.use(
|
||||
// Any status code that lie within the range of 2xx cause this function to trigger
|
||||
function (response) {
|
||||
return response
|
||||
},
|
||||
|
||||
// Any status codes that falls outside the range of 2xx cause this function to trigger
|
||||
function ({ response }) {
|
||||
const error = new Error(response.data?.message)
|
||||
|
||||
error.code = response.data?.__type
|
||||
error.name = response.data?.__type
|
||||
error.statusCode = response.status
|
||||
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
export default instance
|
||||
|
||||
@@ -15,7 +15,6 @@ import amplifyconfig from './amplifyconfiguration.json'
|
||||
import stylesheet from './app.css?url'
|
||||
|
||||
Amplify.configure(amplifyconfig)
|
||||
const queryClient = new QueryClient()
|
||||
|
||||
export const links = () => [
|
||||
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
|
||||
@@ -51,6 +50,8 @@ export function Layout({ children }) {
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const queryClient = new QueryClient()
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AuthProvider>
|
||||
@@ -86,6 +87,7 @@ export function ErrorBoundary({ error }) {
|
||||
<main className="pt-16 p-4 container mx-auto">
|
||||
<h1>{message}</h1>
|
||||
<p>{details}</p>
|
||||
|
||||
{stack && (
|
||||
<pre className="w-full p-4 overflow-x-auto">
|
||||
<code>{stack}</code>
|
||||
|
||||
@@ -52,15 +52,34 @@ function SignIn() {
|
||||
const { data } = await axios.get(`/search/lookup/${username}`)
|
||||
return data
|
||||
},
|
||||
})
|
||||
|
||||
const onSubmit = async ({ username }) => {
|
||||
const data = await mutateAsync({ username })
|
||||
|
||||
onSuccess: (data) => {
|
||||
setSearchParams((searchParams) => {
|
||||
searchParams.set('state', encode(data))
|
||||
return searchParams
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const formError = (message) => {
|
||||
setError('username', {
|
||||
type: 'manual',
|
||||
message,
|
||||
})
|
||||
}
|
||||
|
||||
const onSubmit = async ({ username }) => {
|
||||
try {
|
||||
await mutateAsync({ username })
|
||||
} catch ({ message }) {
|
||||
switch (message) {
|
||||
case 'User not found.':
|
||||
return formError(
|
||||
'Não encontramos sua conta. Por favor, verifique se seu Email ou CPF estão corretos.',
|
||||
)
|
||||
default:
|
||||
return formError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user