18 lines
495 B
TypeScript
18 lines
495 B
TypeScript
|
|
import { error } from '@sveltejs/kit';
|
||
|
|
import { ImporterError } from './recipes/importer';
|
||
|
|
|
||
|
|
export function mapImporterError(e: unknown): never {
|
||
|
|
if (e instanceof ImporterError) {
|
||
|
|
const status =
|
||
|
|
e.code === 'INVALID_URL' || e.code === 'DOMAIN_BLOCKED'
|
||
|
|
? e.code === 'DOMAIN_BLOCKED'
|
||
|
|
? 403
|
||
|
|
: 400
|
||
|
|
: e.code === 'NO_RECIPE_FOUND'
|
||
|
|
? 422
|
||
|
|
: 502; // FETCH_FAILED
|
||
|
|
error(status, { message: e.message, code: e.code });
|
||
|
|
}
|
||
|
|
throw e;
|
||
|
|
}
|