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,16 +113,21 @@ export const attemptLegacyImport = async (
config: Config,
id: string
): Promise<GuildData | null> => {
const legacyGuildData = await fetchLegacyServer(config, id);
if (!legacyGuildData) {
// Means there is no legacy data.
try {
const legacyGuildData = await fetchLegacyServer(config, id);
if (!legacyGuildData) {
// Means there is no legacy data.
return null;
}
const transformed = transformLegacyGuild(legacyGuildData);
await config.kv.guildData.put(id, transformed);
return transformed;
} catch (e) {
console.error('attemptLegacyImport errored:', e);
return null;
}
const transformed = transformLegacyGuild(legacyGuildData);
await config.kv.guildData.put(id, transformed);
return transformed;
};
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 serverError = (error: Error) => {
console.error(error);
console.trace();
return json({ error: 'internal server error' }, { status: 500 });
};
export const notImplemented = () => json({ error: 'not implemented' }, { status: 501 });