Skip to content

Commit

Permalink
fix: bring back error message for Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Nov 3, 2022
1 parent f49cccd commit a39677d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/lib/misc/ErrorHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ export const NO_PACKAGE_ERROR = new Error(
)
);

const NOTION_INFO_LINK =
'https://www.notion.so/help/export-your-content#export-as-html';
export const UNSUPPORTED_FORMAT_MD = new Error(
renderToStaticMarkup(
<>
Markdown support has been removed, please Export as HTML:{' '}
<a target="_blank" href="${NOTION_INFO_LINK}">
${NOTION_INFO_LINK}
</a>
</>
)
);

export default function ErrorHandler(res: express.Response, err: Error) {
if (process.env.NODE_ENV === 'production') {
Sentry.captureException(err);
Expand Down
5 changes: 0 additions & 5 deletions src/routes/upload/helpers/TriggerUnsupportedFormat.ts

This file was deleted.

17 changes: 13 additions & 4 deletions src/routes/upload/helpers/handleUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import StorageHandler from '../../../lib/storage/StorageHandler';
import { PrepareDeck } from '../../../lib/parser/DeckParser';
import Settings from '../../../lib/parser/Settings';
import { ZipHandler } from '../../../lib/anki/zip';
import ErrorHandler, { NO_PACKAGE_ERROR } from '../../../lib/misc/ErrorHandler';
import ErrorHandler, {
NO_PACKAGE_ERROR,
UNSUPPORTED_FORMAT_MD,
} from '../../../lib/misc/ErrorHandler';
import Package from '../../../lib/parser/Package';
import cleanDeckName from './cleanDeckname';
import { registerUploadSize } from './registerUploadSize';
Expand All @@ -19,7 +22,7 @@ export default async function handleUpload(
try {
const files = req.files as Express.Multer.File[];
let packages: Package[] = [];

let hasMarkdown = false;
for (const file of files) {
const filename = file.originalname;
const settings = new Settings(req.body || {});
Expand All @@ -38,7 +41,7 @@ export default async function handleUpload(
packages = packages.concat(pkg);
}
} else if (filename.match(/.md$/)) {
TriggerUnsupportedFormat();
hasMarkdown = true;
} else {
const zipHandler = new ZipHandler();
/* @ts-ignore */
Expand All @@ -49,6 +52,8 @@ export default async function handleUpload(
if (d) {
packages.push(new Package(d.name, d.apkg));
}
} else if (fileName.match(/.md$/)) {
hasMarkdown = true;
}
}
}
Expand Down Expand Up @@ -90,7 +95,11 @@ export default async function handleUpload(
} else if (packages.length > 1) {
sendBundle(packages, storage, res);
} else {
ErrorHandler(res, NO_PACKAGE_ERROR);
if (hasMarkdown) {
ErrorHandler(res, UNSUPPORTED_FORMAT_MD);
} else {
ErrorHandler(res, NO_PACKAGE_ERROR);
}
}
} catch (err) {
captureException(err);
Expand Down

0 comments on commit a39677d

Please sign in to comment.