Skip to content
Open
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
9 changes: 9 additions & 0 deletions packages/client/components/i18n/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useLingui } from "@lingui-solid/solid/macro";
import { API } from "stoat.js";

const RE_BREAK = /\s*\n\s*/g;

/**
* Translate any error
*/
Expand Down Expand Up @@ -159,6 +161,13 @@ export function useError() {
) {
const message = (error as { message: string }).message.trim();
if (message) return message;
} else if (typeof error === "string") {
//Strip HTML from string
const p = document.createElement("html");
p.innerHTML = error;
p.querySelector("head")?.remove();
p.querySelector("[role=contentinfo]")?.remove();
error = p.textContent.trim().replace(RE_BREAK, ". ");
}

return t`Something went wrong! ${error}`;
Expand Down
9 changes: 8 additions & 1 deletion packages/client/components/modal/modals/Error2.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Trans } from "@lingui-solid/solid/macro";
import { styled } from "styled-system/jsx";

import { useError } from "@revolt/i18n";
import { Dialog, DialogProps, iconSize } from "@revolt/ui";
Expand All @@ -7,6 +8,12 @@ import MdError from "@material-design-icons/svg/outlined/error.svg?component-sol

import { Modals } from "../types";

const Error = styled("div", {
base: {
whiteSpace: "pre-wrap",
},
});

export function Error2Modal(props: DialogProps & Modals & { type: "error2" }) {
const err = useError();

Expand All @@ -18,7 +25,7 @@ export function Error2Modal(props: DialogProps & Modals & { type: "error2" }) {
title={<Trans>An error occurred.</Trans>}
actions={[{ text: <Trans>OK</Trans> }]}
>
{err(props.error)}
<Error>{err(props.error)}</Error>
</Dialog>
);
}
Loading