@nevis-security/nevis-mobile-authentication-sdk-react
Version:
React Native plugin for Nevis Mobile Authentication SDK. Supports only mobile.
88 lines (81 loc) • 2.87 kB
text/typescript
/**
* Copyright © 2024 Nevis Security AG. All rights reserved.
*/
import { DeviceInformationSyncClockSkewTooBigError } from './DeviceInformationSyncClockSkewTooBigError';
import { DeviceInformationSyncDeviceProtectionError } from './DeviceInformationSyncDeviceProtectionError';
import type { DeviceInformationSyncError } from './DeviceInformationSyncError';
import { DeviceInformationSyncNetworkError } from './DeviceInformationSyncNetworkError';
import { DeviceInformationSyncNoDeviceLockError } from './DeviceInformationSyncNoDeviceLockError';
import { DeviceInformationSyncOperationNotSupportedByBackendError } from './DeviceInformationSyncOperationNotSupportedByBackendError';
import { DeviceInformationSyncUnknownError } from './DeviceInformationSyncUnknownError';
import { ErrorConverter } from '../../ErrorConverter';
enum DeviceInformationSyncErrorType {
ClockSkewTooBig,
DeviceProtectionError,
NetworkError,
NoDeviceLockError,
OperationNotSupportedByBackend,
Unknown,
}
export class DeviceInformationSyncErrorConverter extends ErrorConverter<DeviceInformationSyncError> {
convert(): DeviceInformationSyncError {
const subtype =
DeviceInformationSyncErrorType[
this.error.type as keyof typeof DeviceInformationSyncErrorType
];
switch (subtype) {
case DeviceInformationSyncErrorType.ClockSkewTooBig:
if (this.error.server) {
return new DeviceInformationSyncClockSkewTooBigError(
this.error.server,
this.error.description,
this.error.cause
);
}
return new DeviceInformationSyncUnknownError(
this.error.description,
this.error.cause
);
case DeviceInformationSyncErrorType.DeviceProtectionError:
return new DeviceInformationSyncDeviceProtectionError(
this.error.description,
this.error.cause
);
case DeviceInformationSyncErrorType.NetworkError:
if (this.error.server) {
return new DeviceInformationSyncNetworkError(
this.error.server,
this.error.description,
this.error.cause
);
}
return new DeviceInformationSyncUnknownError(
this.error.description,
this.error.cause
);
case DeviceInformationSyncErrorType.NoDeviceLockError:
return new DeviceInformationSyncNoDeviceLockError(
this.error.description,
this.error.cause
);
case DeviceInformationSyncErrorType.OperationNotSupportedByBackend:
if (this.error.server) {
return new DeviceInformationSyncOperationNotSupportedByBackendError(
this.error.server,
this.error.description,
this.error.cause
);
}
return new DeviceInformationSyncUnknownError(
this.error.description,
this.error.cause
);
case DeviceInformationSyncErrorType.Unknown:
return new DeviceInformationSyncUnknownError(
this.error.description,
this.error.cause,
this.error.server
);
}
}
}