Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't bail on error when scraping all #4442

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions ui/v2.5/src/components/Tagger/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useLocalForage } from "src/hooks/LocalForage";
import { useToast } from "src/hooks/Toast";
import { ConfigurationContext } from "src/hooks/Config";
import { ITaggerSource, SCRAPER_PREFIX, STASH_BOX_PREFIX } from "./constants";
import { errorToString } from "src/utils";

export interface ITaggerContextState {
config: ITaggerConfig;
Expand Down Expand Up @@ -293,21 +294,29 @@ export const TaggerContext: React.FC = ({ children }) => {
return;
}

const results = await queryScrapeScene(currentSource.sourceInput, sceneID);
let newResult: ISceneQueryResult;

if (results.error) {
newResult = { error: results.error.message };
} else if (results.errors) {
newResult = { error: results.errors.toString() };
} else {
newResult = {
results: results.data.scrapeSingleScene.map((r) => ({
...r,
// scenes are already resolved if they are scraped via fragment
resolved: true,
})),
};
try {
const results = await queryScrapeScene(
currentSource.sourceInput,
sceneID
);

if (results.error) {
newResult = { error: results.error.message };
} else if (results.errors) {
newResult = { error: results.errors.toString() };
} else {
newResult = {
results: results.data.scrapeSingleScene.map((r) => ({
...r,
// scenes are already resolved if they are scraped via fragment
resolved: true,
})),
};
}
} catch (err: unknown) {
newResult = { error: errorToString(err) };
}

setSearchResults((current) => {
Expand Down
12 changes: 2 additions & 10 deletions ui/v2.5/src/hooks/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
useMemo,
} from "react";
import { Toast } from "react-bootstrap";
import { errorToString } from "src/utils";

interface IToast {
header?: string;
Expand Down Expand Up @@ -67,16 +68,7 @@ export const useToast = () => {
});
},
error(error: unknown) {
let message;
if (error instanceof Error) {
message = error.message;
}
if (!message) {
message = String(error);
}
if (!message) {
message = "Unknown error";
}
const message = errorToString(error);

console.error(error);
addToast({
Expand Down
15 changes: 15 additions & 0 deletions ui/v2.5/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@ import { ApolloError } from "@apollo/client";

export const apolloError = (error: unknown) =>
error instanceof ApolloError ? error.message : "";

export function errorToString(error: unknown) {
let message;
if (error instanceof Error) {
message = error.message;
}
if (!message) {
message = String(error);
}
if (!message) {
message = "Unknown error";
}

return message;
}
Loading