Adds compatibility for skipped checks for server host reasons

This commit is contained in:
Alicia Sykes 2023-07-29 11:40:03 +01:00
parent dc651a7b1e
commit 7422d22538
2 changed files with 20 additions and 13 deletions

View File

@ -167,6 +167,9 @@ p {
}
pre {
color: ${colors.danger};
&.info {
color: ${colors.warning};
}
}
`;
@ -202,7 +205,9 @@ const jobNames = [
'sitemap',
'hsts',
'security-txt',
'social-tags',
'linked-pages',
'mail-server',
// 'whois',
'features',
'carbon',
@ -360,7 +365,7 @@ const ProgressLoader = (props: { loadStatus: LoadingJob[], showModal: (err: Reac
}
};
const showErrorModal = (name: string, state: LoadingState, timeTaken: number | undefined, error: string) => {
const showErrorModal = (name: string, state: LoadingState, timeTaken: number | undefined, error: string, isInfo?: boolean) => {
const errorContent = (
<ErrorModalContent>
<Heading as="h3">Error Details for {name}</Heading>
@ -368,7 +373,8 @@ const ProgressLoader = (props: { loadStatus: LoadingJob[], showModal: (err: Reac
The {name} job failed with an {state} state after {timeTaken} ms.
The server responded with the following error:
</p>
<pre>{error}</pre>
{ /* If isInfo == true, then add .info className to pre */}
<pre className={isInfo ? 'info' : 'error'}>{error}</pre>
</ErrorModalContent>
);
props.showModal(errorContent);
@ -409,6 +415,7 @@ const ProgressLoader = (props: { loadStatus: LoadingJob[], showModal: (err: Reac
<i>{(timeTaken && state !== 'loading') ? ` Took ${timeTaken} ms` : '' }</i>
{ (retry && state !== 'success' && state !== 'loading') && <FailedJobActionButton onClick={retry}> Retry</FailedJobActionButton> }
{ (error && state === 'error') && <FailedJobActionButton onClick={() => showErrorModal(name, state, timeTaken, error)}> Show Error</FailedJobActionButton> }
{ (error && state === 'skipped') && <FailedJobActionButton onClick={() => showErrorModal(name, state, timeTaken, error, true)}> Show Reason</FailedJobActionButton> }
</li>
);
})

View File

@ -38,21 +38,20 @@ const useMotherOfAllHooks = <ResultType = any>(params: UseIpAddressProps<ResultT
const doTheFetch = () => {
return fetchRequest()
.then((res: any) => {
if (!res) {
if (!res) { // No response :(
updateLoadingJobs(jobId, 'error', res.error || 'No response', reset);
} else if (res.error) { // Response returned an error message
updateLoadingJobs(jobId, 'error', res.error, reset);
throw new Error('No response');
} else if (res.skipped) { // Response returned a skipped message
updateLoadingJobs(jobId, 'skipped', res.skipped, reset);
} else { // Yay, everything went to plan :)
setResult(res);
updateLoadingJobs(jobId, 'success', '', undefined, res);
}
if (res.error) {
updateLoadingJobs(jobId, 'error', res.error, reset);
throw new Error(res.error);
}
// All went to plan, set results and mark as done
setResult(res);
updateLoadingJobs(jobId, 'success', '', undefined, res);
})
.catch((err) => {
// Something fucked up, log the error
updateLoadingJobs(jobId, 'error', err.error || err.message, reset);
// Something fucked up
updateLoadingJobs(jobId, 'error', err.error || err.message || 'Unknown error', reset);
throw err;
})
}
@ -69,6 +68,7 @@ const useMotherOfAllHooks = <ResultType = any>(params: UseIpAddressProps<ResultT
pending: `Updating Data (${jobId})`,
success: `Completed (${jobId})`,
error: `Failed to update (${jobId})`,
skipped: `Skipped job (${jobId}), as no valid results for host`,
};
// Initiate fetch, and show progress toast
toast.promise(fetchyFetch, toastOptions).catch(() => {});