27 lines
657 B
TypeScript
27 lines
657 B
TypeScript
import { t } from '@/i18n'
|
|
import type { VariantCause } from '@/composables/useMediaVariants'
|
|
|
|
const PAYLOAD_TOO_LARGE = 413
|
|
const UNSUPPORTED_MEDIA_TYPE = 415
|
|
const UNPROCESSABLE = 422
|
|
|
|
export function causeText(cause: string) {
|
|
if (cause === 'too_large') {
|
|
return t('Image too large')
|
|
}
|
|
if (cause === 'unsupported_format') {
|
|
return t('Unsupported source format')
|
|
}
|
|
return t('Generation failed')
|
|
}
|
|
|
|
export function causeOfStatus(status: number): VariantCause | null {
|
|
if (status === PAYLOAD_TOO_LARGE) {
|
|
return 'too_large'
|
|
}
|
|
if (status === UNSUPPORTED_MEDIA_TYPE || status === UNPROCESSABLE) {
|
|
return 'unsupported_format'
|
|
}
|
|
return null
|
|
}
|