mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-25 13:51:13 +00:00
parent
fe28c691e3
commit
b40a3c3e27
10 changed files with 25 additions and 22 deletions
|
@ -49,7 +49,10 @@ export default async (req: Request, res: Response) => {
|
|||
let errorPageData: ErrorPageData | undefined = undefined;
|
||||
let try_site = await client.getSite();
|
||||
|
||||
if (try_site.state === "failed" && try_site.msg === "not_logged_in") {
|
||||
if (
|
||||
try_site.state === "failed" &&
|
||||
try_site.err.message === "not_logged_in"
|
||||
) {
|
||||
console.error(
|
||||
"Incorrect JWT token, skipping auth so frontend can remove jwt cookie",
|
||||
);
|
||||
|
@ -85,22 +88,23 @@ export default async (req: Request, res: Response) => {
|
|||
}
|
||||
} else if (try_site.state === "failed") {
|
||||
res.status(500);
|
||||
errorPageData = getErrorPageData(new Error(try_site.msg), site);
|
||||
errorPageData = getErrorPageData(new Error(try_site.err.message), site);
|
||||
}
|
||||
|
||||
const error = Object.values(routeData).find(
|
||||
res => res.state === "failed" && res.msg !== "couldnt_find_object", // TODO: find a better way of handling errors
|
||||
res =>
|
||||
res.state === "failed" && res.err.message !== "couldnt_find_object", // TODO: find a better way of handling errors
|
||||
) as FailedRequestState | undefined;
|
||||
|
||||
// Redirect to the 404 if there's an API error
|
||||
if (error) {
|
||||
console.error(error.msg);
|
||||
console.error(error.err);
|
||||
|
||||
if (error.msg === "instance_is_private") {
|
||||
if (error.err.message === "instance_is_private") {
|
||||
return res.redirect(`/signup`);
|
||||
} else {
|
||||
res.status(500);
|
||||
errorPageData = getErrorPageData(new Error(error.msg), site);
|
||||
errorPageData = getErrorPageData(new Error(error.err.message), site);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,8 +88,7 @@ export class ImageUploadForm extends Component<
|
|||
toast(JSON.stringify(res), "danger");
|
||||
}
|
||||
} else if (res.state === "failed") {
|
||||
console.error(res.msg);
|
||||
toast(res.msg, "danger");
|
||||
toast(res.err.message, "danger");
|
||||
}
|
||||
|
||||
i.setState({ loading: false });
|
||||
|
|
|
@ -494,10 +494,10 @@ export class MarkdownTextArea extends Component<
|
|||
}
|
||||
} else if (res.state === "failed") {
|
||||
i.setState({ imageUploadStatus: undefined });
|
||||
console.error(res.msg);
|
||||
toast(res.msg, "danger");
|
||||
console.error(res.err.message);
|
||||
toast(res.err.message, "danger");
|
||||
|
||||
throw res.msg;
|
||||
throw res.err;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -510,8 +510,8 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
|
|||
toast(JSON.stringify(res), "danger");
|
||||
}
|
||||
} else if (res.state === "failed") {
|
||||
console.error(res.msg);
|
||||
toast(res.msg, "danger");
|
||||
console.error(res.err.message);
|
||||
toast(res.err.message, "danger");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -73,10 +73,10 @@ async function handleLoginSubmit(i: Login, event: any) {
|
|||
});
|
||||
switch (loginRes.state) {
|
||||
case "failed": {
|
||||
if (loginRes.msg === "missing_totp_token") {
|
||||
if (loginRes.err.message === "missing_totp_token") {
|
||||
i.setState({ show2faModal: true });
|
||||
} else {
|
||||
toast(I18NextService.i18n.t(loginRes.msg), "danger");
|
||||
toast(I18NextService.i18n.t(loginRes.err.message), "danger");
|
||||
}
|
||||
|
||||
i.setState({ loginRes });
|
||||
|
|
|
@ -388,7 +388,7 @@ export class Signup extends Component<any, State> {
|
|||
});
|
||||
switch (registerRes.state) {
|
||||
case "failed": {
|
||||
toast(registerRes.msg, "danger");
|
||||
toast(registerRes.err.message, "danger");
|
||||
i.setState({ registerRes: EMPTY_REQUEST });
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -864,7 +864,7 @@ export class Inbox extends Component<any, InboxState> {
|
|||
toast(I18NextService.i18n.t("edit"));
|
||||
this.findAndUpdateComment(res);
|
||||
} else if (res.state === "failed") {
|
||||
toast(res.msg, "danger");
|
||||
toast(res.err.message, "danger");
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -163,7 +163,7 @@ async function handleGenerateTotp(i: Settings) {
|
|||
const generateTotpRes = await HttpService.client.generateTotpSecret();
|
||||
|
||||
if (generateTotpRes.state === "failed") {
|
||||
toast(generateTotpRes.msg, "danger");
|
||||
toast(generateTotpRes.err.message, "danger");
|
||||
} else {
|
||||
i.setState({ show2faModal: true });
|
||||
}
|
||||
|
|
|
@ -190,8 +190,8 @@ function handleImageUpload(i: PostForm, event: any) {
|
|||
toast(JSON.stringify(res), "danger");
|
||||
}
|
||||
} else if (res.state === "failed") {
|
||||
console.error(res.msg);
|
||||
toast(res.msg, "danger");
|
||||
console.error(res.err.message);
|
||||
toast(res.err.message, "danger");
|
||||
i.setState({ imageLoading: false });
|
||||
}
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ type LoadingRequestState = typeof LOADING_REQUEST;
|
|||
|
||||
export type FailedRequestState = {
|
||||
state: "failed";
|
||||
msg: string;
|
||||
err: Error;
|
||||
};
|
||||
|
||||
type SuccessRequestState<T> = {
|
||||
|
@ -71,7 +71,7 @@ class WrappedLemmyHttpClient {
|
|||
}
|
||||
return {
|
||||
state: "failed",
|
||||
msg: error,
|
||||
err: error,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue