Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion KeychainExample/.detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
type: 'ios.simulator',
headless: Boolean(process.env.CI),
device: {
type: 'iPhone 15 Pro',
type: 'iPhone 16 Pro',
},
},
attached: {
Expand Down
2 changes: 1 addition & 1 deletion KeychainExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios --simulator 'iPhone 15 Pro'",
"ios": "react-native run-ios",
"build:android": "npm run mkdist && react-native bundle --entry-file index.js --platform android --dev false --bundle-output dist/main.android.jsbundle --assets-dest dist/res",
"build:ios": "npm run mkdist && react-native bundle --entry-file index.js --platform ios --dev false --bundle-output dist/main.ios.jsbundle --assets-dest dist/assets",
"mkdist": "node -e \"require('node:fs').mkdirSync('dist', { recursive: true, mode: 0o755 })\"",
Expand Down
38 changes: 38 additions & 0 deletions src/KeychainError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ERROR_CODE } from './enums';

const RETRYABLE_ERROR_CODES = [
ERROR_CODE.BIOMETRIC_TIMEOUT,
ERROR_CODE.BIOMETRIC_LOCKOUT,
ERROR_CODE.BIOMETRIC_TEMPORARILY_UNAVAILABLE,
];

/**
* Custom error class for encapsulating the native error objects.
*/
export class KeychainError extends Error {
readonly code: ERROR_CODE;
readonly retryable: boolean;
readonly cause: Error | null;

constructor(message: string, code: ERROR_CODE, cause?: Error) {
super(message);

this.name = 'KeychainError';
this.code = code;
this.retryable = RETRYABLE_ERROR_CODES.includes(code);
this.cause = cause ?? null;
}

static parse(err: unknown) {
if (err instanceof Error) {
const code =
'code' in err ? (err.code as ERROR_CODE) : ERROR_CODE.INTERNAL_ERROR;

return new KeychainError(err.message, code, err);
}

return err;
}
}

export default KeychainError;
Loading