-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from Renumics/feature/special-view-for-errors…
…-on-load Feature/special view for errors on load
- Loading branch information
Showing
6 changed files
with
104 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Problem } from '../types'; | ||
|
||
const DEFAULT_PROBLEM: Problem = { | ||
type: 'UndefinedApiError', | ||
title: 'Undefined API Error', | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export async function parseError(error: any): Promise<Problem> { | ||
if (!error.response?.json) { | ||
return DEFAULT_PROBLEM; | ||
} | ||
|
||
try { | ||
return (await error.response.json()) as Problem; | ||
} catch { | ||
return DEFAULT_PROBLEM; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import application from '../application'; | ||
import { useDataset } from '../lib'; | ||
import { Problem } from '../types'; | ||
import Center from './ui/Center'; | ||
import tw from 'twin.macro'; | ||
|
||
interface Props { | ||
problem: Problem; | ||
} | ||
|
||
const Button = tw.button`border border-gray-600 rounded px-2 py-1 text-sm`; | ||
|
||
const LoadingError = ({ problem }: Props): JSX.Element => { | ||
const reload = () => location.reload(); | ||
const browse = () => useDataset.getState().clearLoadingError(); | ||
const close = () => window.close(); | ||
|
||
return ( | ||
<Center tw="flex flex-col gap-y-4 text-midnight-600"> | ||
<div tw="flex flex-col items-center"> | ||
<h1 tw="text-lg">Failed to load your dataset</h1> | ||
<p tw="text-sm text-gray-800">(with the following API error)</p> | ||
</div> | ||
<div tw="border border-red-600 rounded bg-red-100 divide-y divide-red-600"> | ||
<h2 tw="font-bold p-1">{problem.title}</h2> | ||
{problem.detail && <p tw="p-1 text-sm">{problem.detail}</p>} | ||
</div> | ||
<div tw="flex flex-row gap-x-2"> | ||
<Button onClick={reload}>Reload</Button> | ||
{application.filebrowsingAllowed && ( | ||
<Button onClick={browse}>Open another dataset</Button> | ||
)} | ||
<Button onClick={close}>Close</Button> | ||
</div> | ||
</Center> | ||
); | ||
}; | ||
|
||
export default LoadingError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import tw from 'twin.macro'; | ||
|
||
const Center = tw.div`w-full h-full flex justify-center items-center`; | ||
|
||
export default Center; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters