attemptLegacyImport should not break the entire request when it fails

This commit is contained in:
41666 2022-02-02 13:52:01 -05:00
parent 140f9d566b
commit c7bfed8bae
2 changed files with 14 additions and 8 deletions

View file

@ -113,6 +113,7 @@ export const attemptLegacyImport = async (
config: Config, config: Config,
id: string id: string
): Promise<GuildData | null> => { ): Promise<GuildData | null> => {
try {
const legacyGuildData = await fetchLegacyServer(config, id); const legacyGuildData = await fetchLegacyServer(config, id);
if (!legacyGuildData) { if (!legacyGuildData) {
// Means there is no legacy data. // Means there is no legacy data.
@ -123,6 +124,10 @@ export const attemptLegacyImport = async (
await config.kv.guildData.put(id, transformed); await config.kv.guildData.put(id, transformed);
return transformed; return transformed;
} catch (e) {
console.error('attemptLegacyImport errored:', e);
return null;
}
}; };
export const getGuildMember = async ( export const getGuildMember = async (

View file

@ -36,6 +36,7 @@ export const forbidden = () => json({ error: 'forbidden' }, { status: 403 });
export const notFound = () => json({ error: 'not found' }, { status: 404 }); export const notFound = () => json({ error: 'not found' }, { status: 404 });
export const serverError = (error: Error) => { export const serverError = (error: Error) => {
console.error(error); console.error(error);
console.trace();
return json({ error: 'internal server error' }, { status: 500 }); return json({ error: 'internal server error' }, { status: 500 });
}; };
export const notImplemented = () => json({ error: 'not implemented' }, { status: 501 }); export const notImplemented = () => json({ error: 'not implemented' }, { status: 501 });