isCommitErrorCode()
function isCommitErrorCode(value): value is CommitErrorCode;
Defined in: packages/rxdb-plugin-working-tree/src/commit/commit-error-codes.ts:210
判定一个值是否为已登记的提交错误码
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | 待判定的值,通常取自 catch 到的对象上的 code |
Returns
value is CommitErrorCode
命中 COMMIT_ERROR_CODES 时为 true
Remarks
收窄到 CommitErrorCode,让调用方能在 switch 里拿到穷尽性检查。
未登记的字符串(如 commit_conflict——它是返回值不是异常)与非字符串一律为 false。
Example
try {
await database.commit('保存草稿');
} catch (error) {
const code: unknown = (error as { code?: unknown }).code;
if (isCommitErrorCode(code) && code === CommitErrorCode.commit_graph_corrupted) {
// 该分支 corrupted_read_only:只能读当前投影与导出诊断
}
throw error;
}