44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
export type PerformanceSurveyBrowserImageErrorCode =
|
|
| 'BROWSER_CAPABILITY_UNAVAILABLE'
|
|
| 'BROWSER_DECODE_UNAVAILABLE'
|
|
| 'WORKER_UNAVAILABLE'
|
|
| 'WORKER_TIMEOUT'
|
|
| 'CANVAS_UNAVAILABLE'
|
|
| 'CANVAS_EXPORT_UNAVAILABLE'
|
|
| 'SOURCE_FORMAT_UNSUPPORTED'
|
|
| 'SOURCE_DECODE_FAILED'
|
|
| 'SOURCE_DIMENSIONS_INVALID'
|
|
| 'SOURCE_WIDTH_LIMIT'
|
|
| 'SOURCE_PIXEL_LIMIT'
|
|
| 'SOURCE_SLICE_LIMIT'
|
|
| 'SOURCE_COUNT_LIMIT'
|
|
| 'NO_SOURCE_IMAGES'
|
|
| 'PROCESSING_FAILED'
|
|
|
|
const BROWSER_CAPABILITY_ERROR_CODES = new Set<PerformanceSurveyBrowserImageErrorCode>([
|
|
'BROWSER_CAPABILITY_UNAVAILABLE',
|
|
'BROWSER_DECODE_UNAVAILABLE',
|
|
'WORKER_UNAVAILABLE',
|
|
'WORKER_TIMEOUT',
|
|
'CANVAS_UNAVAILABLE',
|
|
'CANVAS_EXPORT_UNAVAILABLE',
|
|
])
|
|
|
|
export class PerformanceSurveyBrowserImageError extends Error {
|
|
readonly code: PerformanceSurveyBrowserImageErrorCode
|
|
|
|
constructor(code: PerformanceSurveyBrowserImageErrorCode, message: string) {
|
|
super(message)
|
|
this.name = 'PerformanceSurveyBrowserImageError'
|
|
this.code = code
|
|
Object.setPrototypeOf(this, PerformanceSurveyBrowserImageError.prototype)
|
|
}
|
|
}
|
|
|
|
export function isPerformanceSurveyBrowserCapabilityError(
|
|
error: unknown,
|
|
): error is PerformanceSurveyBrowserImageError {
|
|
return error instanceof PerformanceSurveyBrowserImageError
|
|
&& BROWSER_CAPABILITY_ERROR_CODES.has(error.code)
|
|
}
|