Skip to content

Commit

Permalink
Use custom Axios instance + better timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
harryttd committed Oct 18, 2023
1 parent c1dc4dc commit eeb9780
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/components/Faucet/FaucetRequestButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import {
VerifyResponse,
} from "../../lib/Types"

export const api = axios.create({
baseURL: Config.application.backendUrl,
timeout: 10_000,
timeoutErrorMessage: "Connection timeout exceeded. Please try again.",
})

const { minTez, maxTez } = Config.application
// Compute the step for the Tezos amount range slider.
const tezRangeStep = (() => {
Expand Down Expand Up @@ -175,10 +181,9 @@ export default function FaucetRequestButton({
captchaToken,
}

const { data }: { data: ChallengeResponse } = await axios.post(
`${Config.application.backendUrl}/challenge`,
input,
{ timeout: 5000 }
const { data }: { data: ChallengeResponse } = await api.post(
"/challenge",
input
)

if (validateChallenge(data)) {
Expand All @@ -187,7 +192,9 @@ export default function FaucetRequestButton({
stopLoadingError(data?.message || "Error getting challenge")
}
} catch (err: any) {
stopLoadingError(err?.response?.data.message || "Error getting challenge")
stopLoadingError(
err?.response?.data.message || err?.message || "Error getting challenge"
)
}
return {}
}
Expand All @@ -207,10 +214,9 @@ export default function FaucetRequestButton({
}

try {
const { data }: { data: VerifyResponse } = await axios.post(
`${Config.application.backendUrl}/verify`,
input,
{ timeout: 5000 }
const { data }: { data: VerifyResponse } = await api.post(
"/verify",
input
)

// If there is another challenge
Expand All @@ -231,7 +237,9 @@ export default function FaucetRequestButton({
stopLoadingError("Error verifying solution")
}
} catch (err: any) {
stopLoadingError(err?.response?.data.message || err.message)
stopLoadingError(
err?.response?.data.message || err?.message || err.message
)
}
return {}
}
Expand Down

0 comments on commit eeb9780

Please sign in to comment.