Skip to content

Commit

Permalink
Display service unavailable error accordingly if returned from indexer
Browse files Browse the repository at this point in the history
ref #2584
  • Loading branch information
louischan-oursky committed Oct 18, 2022
2 parents a3ff3da + 34c7c5a commit a1e2e08
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
6 changes: 6 additions & 0 deletions portal/src/error/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export interface TooManyRequestError {
reason: "TooManyRequest";
}

export interface ServiceUnavailableError {
errorName: "ServiceUnavailable";
reason: "ServiceUnavailable";
}

export interface UnknownError {
errorName: "Unknown";
reason: "Unknown";
Expand All @@ -72,6 +77,7 @@ export type APIError =
| UnknownError
| LocalError
| TooManyRequestError
| ServiceUnavailableError
| WebHookDisallowedError
| WebHookDeliveryTimeoutError
| WebHookInvalidResponseError
Expand Down
45 changes: 26 additions & 19 deletions portal/src/graphql/portal/Web3ConfigurationAddCollectionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,38 @@ const Web3ConfigurationAddCollectionForm: React.VFC<AddCollectionSectionProps> =
return;
}

const probeResult = await probeCollection(contractID);
if (probeResult) {
setActiveDialog("largeCollection");
setIsLoading(false);
return;
}
try {
const probeResult = await probeCollection(contractID);
if (probeResult) {
setActiveDialog("largeCollection");
setIsLoading(false);
return;
}

const metadata = await fetchMetadata(contractID);
if (!metadata) {
setIsLoading(false);
return;
}
const metadata = await fetchMetadata(contractID);
if (!metadata) {
setIsLoading(false);
return;
}

if (metadata.tokenType === "erc1155" && !tokenIDs?.length) {
setActiveDialog("tokenTracking");
if (metadata.tokenType === "erc1155" && !tokenIDs?.length) {
setActiveDialog("tokenTracking");
setIsLoading(false);
return;
}

onAdd({
...metadata,
createdAt: DateTime.now().toISO(),
tokenIDs: tokenIDs ?? [],
status: "pending",
});
} catch (_: unknown) {
// Error handled by parent component
setIsLoading(false);
return;
}

onAdd({
...metadata,
createdAt: DateTime.now().toISO(),
tokenIDs: tokenIDs ?? [],
status: "pending",
});
setIsLoading(false);
resetValues();
},
Expand Down
5 changes: 4 additions & 1 deletion portal/src/graphql/portal/Web3ConfigurationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,10 @@ const Web3ConfigurationScreen: React.VFC = function Web3ConfigurationScreen() {

const errorRules: ErrorParseRule[] = useMemo(() => {
return [
makeReasonErrorParseRule("TooManyRequest", "errors.rate-limited"),
makeReasonErrorParseRule(
"ServiceUnavailable",
"errors.service-unavailable"
),
makeReasonErrorParseRule("BadNFTCollection", "errors.bad-nft-collection"),
];
}, []);
Expand Down
2 changes: 1 addition & 1 deletion portal/src/locale-data/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"errors.invalid-address": "Please input a valid contract address.",
"errors.invalid-token-id": "Please input a valid token ID.",
"errors.duplicated-contract": "Duplicated contract address.",
"errors.rate-limited": "You have exceeded the rate limit. Please Try again later.",
"errors.service-unavailable": "Service Unavailable. Please Try again later.",
"errors.bad-nft-collection": "This NFT collection is either not supported or is from another network.",

"TodoButtonWrapper.dialog-title": "Feature Not Ready",
Expand Down

0 comments on commit a1e2e08

Please sign in to comment.