fix(mobile): handle file picker cancellation

This commit is contained in:
key
2026-07-29 02:01:45 +08:00
parent fd59421574
commit cb928edafd
18 changed files with 202 additions and 26 deletions
+28
View File
@@ -0,0 +1,28 @@
export const FILE_SELECTION_CANCELLED = 'FILE_SELECTION_CANCELLED';
export class FileSelectionCancelledError extends Error {
readonly code = FILE_SELECTION_CANCELLED;
constructor(label: string) {
super(`未选择${label}`);
this.name = 'FileSelectionCancelledError';
}
}
const failureSignal = (failure: unknown): string => {
if (typeof failure === 'string') return failure;
if (!failure || typeof failure !== 'object') return '';
const value = failure as { errMsg?: unknown; message?: unknown };
return String(value.errMsg || value.message || '');
};
export const fileSelectionFailure = (failure: unknown, label: string): Error => {
const signal = failureSignal(failure).toLowerCase();
if (signal.includes('cancel')) return new FileSelectionCancelledError(label);
return new Error(`无法选择${label},请重试`);
};
export const isFileSelectionCancelled = (error: unknown): boolean =>
error instanceof FileSelectionCancelledError
|| Boolean(error && typeof error === 'object'
&& (error as { code?: unknown }).code === FILE_SELECTION_CANCELLED);