@ledgerhq/errors
Advanced tools
Comparing version 6.16.0-nightly.3 to 6.16.0
# @ledgerhq/errors | ||
## 6.16.0-nightly.3 | ||
## 6.16.0 | ||
### Patch Changes | ||
### Minor Changes | ||
- [#5432](https://github.com/LedgerHQ/ledger-live/pull/5432) [`4d1aade53c`](https://github.com/LedgerHQ/ledger-live/commit/4d1aade53cd33f8e7548ce340f54fbb834bdcdcb) Thanks [@alexandremgo](https://github.com/alexandremgo)! - chore: refactoring TransportStatusError | ||
- [#4886](https://github.com/LedgerHQ/ledger-live/pull/4886) [`771c9d3c1d`](https://github.com/LedgerHQ/ledger-live/commit/771c9d3c1d138ddd68da2e4f9738e2c41ecaf81b) Thanks [@chabroA](https://github.com/chabroA)! - Add speedup / cancel tx feature for evm | ||
Refactor into a real class in order to improve TS inference | ||
- [#5430](https://github.com/LedgerHQ/ledger-live/pull/5430) [`5964e30bed`](https://github.com/LedgerHQ/ledger-live/commit/5964e30bed11d64a3b7401c6ab51ffc1ad4c427c) Thanks [@hedi-edelbloute](https://github.com/hedi-edelbloute)! - Update documentation v14 ledgerjs | ||
## 6.16.0-nightly.2 | ||
### Patch Changes | ||
### Minor Changes | ||
- [#4819](https://github.com/LedgerHQ/ledger-live/pull/4819) [`c5981ae341`](https://github.com/LedgerHQ/ledger-live/commit/c5981ae3411abc4c8594adf2efcb52aacddac143) Thanks [@haammar-ledger](https://github.com/haammar-ledger)! - Add support for casper blockchain | ||
- [#5430](https://github.com/LedgerHQ/ledger-live/pull/5430) [`5964e30bed`](https://github.com/LedgerHQ/ledger-live/commit/5964e30bed11d64a3b7401c6ab51ffc1ad4c427c) Thanks [@hedi-edelbloute](https://github.com/hedi-edelbloute)! - Update documentation v14 ledgerjs | ||
- [#4987](https://github.com/LedgerHQ/ledger-live/pull/4987) [`e63205b850`](https://github.com/LedgerHQ/ledger-live/commit/e63205b85071538ed2431157a12818d7a8f0ffa9) Thanks [@kallen-ledger](https://github.com/kallen-ledger)! - add 10s timeout to estimate gas | ||
## 6.16.0-nightly.1 | ||
## 6.16.0-next.0 | ||
@@ -23,6 +23,8 @@ ### Minor Changes | ||
## 6.15.1-nightly.0 | ||
- [#5430](https://github.com/LedgerHQ/ledger-live/pull/5430) [`5964e30bed`](https://github.com/LedgerHQ/ledger-live/commit/5964e30bed11d64a3b7401c6ab51ffc1ad4c427c) Thanks [@hedi-edelbloute](https://github.com/hedi-edelbloute)! - Update documentation v14 ledgerjs | ||
### Patch Changes | ||
- [#4819](https://github.com/LedgerHQ/ledger-live/pull/4819) [`c5981ae341`](https://github.com/LedgerHQ/ledger-live/commit/c5981ae3411abc4c8594adf2efcb52aacddac143) Thanks [@haammar-ledger](https://github.com/haammar-ledger)! - Add support for casper blockchain | ||
- [#4987](https://github.com/LedgerHQ/ledger-live/pull/4987) [`e63205b850`](https://github.com/LedgerHQ/ledger-live/commit/e63205b85071538ed2431157a12818d7a8f0ffa9) Thanks [@kallen-ledger](https://github.com/kallen-ledger)! - add 10s timeout to estimate gas | ||
@@ -29,0 +31,0 @@ |
@@ -60,2 +60,5 @@ import { serializeError, deserializeError, createCustomErrorClass, addCustomErrorDeserializer, LedgerErrorConstructor } from "./helpers"; | ||
}>; | ||
export declare const LockedDeviceError: LedgerErrorConstructor<{ | ||
[key: string]: unknown; | ||
}>; | ||
export declare const UnresponsiveDeviceError: LedgerErrorConstructor<{ | ||
@@ -346,3 +349,2 @@ [key: string]: unknown; | ||
}>; | ||
export type CustomErrorClassType = ReturnType<typeof createCustomErrorClass>; | ||
/** | ||
@@ -422,19 +424,6 @@ * Type of a Transport error used to represent all equivalent errors coming from all possible implementation of Transport | ||
*/ | ||
export declare class TransportStatusError extends Error { | ||
statusCode: number; | ||
statusText: string; | ||
/** | ||
* @param statusCode The error status code coming from a Transport implementation | ||
* @param options containing: | ||
* - canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it | ||
* . Ex: LockedDeviceError. Default to true. | ||
*/ | ||
constructor(statusCode: number, { canBeMappedToChildError }?: { | ||
canBeMappedToChildError?: boolean; | ||
}); | ||
export declare function TransportStatusError(statusCode: number): void; | ||
export declare namespace TransportStatusError { | ||
var prototype: Error; | ||
} | ||
export declare class LockedDeviceError extends TransportStatusError { | ||
constructor(message?: string); | ||
} | ||
export type TransportStatusErrorClassType = typeof TransportStatusError | typeof LockedDeviceError; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -22,2 +22,3 @@ import { serializeError, deserializeError, createCustomErrorClass, addCustomErrorDeserializer, } from "./helpers"; | ||
export const DeviceSocketNoBulkStatus = createCustomErrorClass("DeviceSocketNoBulkStatus"); | ||
export const LockedDeviceError = createCustomErrorClass("LockedDeviceError"); | ||
export const UnresponsiveDeviceError = createCustomErrorClass("UnresponsiveDeviceError"); | ||
@@ -231,34 +232,19 @@ export const DisconnectedDevice = createCustomErrorClass("DisconnectedDevice"); | ||
*/ | ||
export class TransportStatusError extends Error { | ||
/** | ||
* @param statusCode The error status code coming from a Transport implementation | ||
* @param options containing: | ||
* - canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it | ||
* . Ex: LockedDeviceError. Default to true. | ||
*/ | ||
constructor(statusCode, { canBeMappedToChildError = true } = {}) { | ||
const statusText = Object.keys(StatusCodes).find(k => StatusCodes[k] === statusCode) || "UNKNOWN_ERROR"; | ||
const smsg = getAltStatusMessage(statusCode) || statusText; | ||
const statusCodeStr = statusCode.toString(16); | ||
const message = `Ledger device: ${smsg} (0x${statusCodeStr})`; | ||
super(message); | ||
this.name = "TransportStatusError"; | ||
this.statusCode = statusCode; | ||
this.statusText = statusText; | ||
// Maps to a LockedDeviceError | ||
if (canBeMappedToChildError && statusCode === StatusCodes.LOCKED_DEVICE) { | ||
return new LockedDeviceError(message); | ||
} | ||
export function TransportStatusError(statusCode) { | ||
const statusText = Object.keys(StatusCodes).find(k => StatusCodes[k] === statusCode) || "UNKNOWN_ERROR"; | ||
const smsg = getAltStatusMessage(statusCode) || statusText; | ||
const statusCodeStr = statusCode.toString(16); | ||
const message = `Ledger device: ${smsg} (0x${statusCodeStr})`; | ||
// Maps to a LockedDeviceError | ||
if (statusCode === StatusCodes.LOCKED_DEVICE) { | ||
throw new LockedDeviceError(message); | ||
} | ||
this.name = "TransportStatusError"; | ||
this.message = message; | ||
this.stack = new Error(message).stack; | ||
this.statusCode = statusCode; | ||
this.statusText = statusText; | ||
} | ||
export class LockedDeviceError extends TransportStatusError { | ||
constructor(message) { | ||
super(StatusCodes.LOCKED_DEVICE, { canBeMappedToChildError: false }); | ||
if (message) { | ||
this.message = message; | ||
} | ||
this.name = "LockedDeviceError"; | ||
} | ||
} | ||
TransportStatusError.prototype = new Error(); | ||
addCustomErrorDeserializer("TransportStatusError", e => new TransportStatusError(e.statusCode)); | ||
//# sourceMappingURL=index.js.map |
@@ -70,22 +70,7 @@ import { AmountRequired, CurrencyNotSupported, TransportStatusError, StatusCodes } from "./index"; | ||
}); | ||
describe("TransportStatusError", () => { | ||
test("TransportStatusError contains the expected name, message, stack, status code and status message (non-regression)", () => { | ||
const error = new TransportStatusError(StatusCodes.UNKNOWN_APDU); | ||
console.log(`${JSON.stringify(error)}`); | ||
expect(error.name).toEqual("TransportStatusError"); | ||
expect(error.message).toEqual("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
expect(error.stack).toContain("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
expect(error.statusText).toEqual("UNKNOWN_APDU"); | ||
expect(error.statusCode).toEqual(0x6d02); | ||
}); | ||
test.only("TransportStatusError should be mapped to a LockedDeviceError on status code 0x5515", () => { | ||
const error = new TransportStatusError(StatusCodes.LOCKED_DEVICE); | ||
expect(error.name).toEqual("LockedDeviceError"); | ||
expect(error.message).toEqual("Ledger device: Locked device (0x5515)"); | ||
expect(error.stack).toContain("Ledger device: Locked device (0x5515)"); | ||
expect(error.statusText).toEqual("LOCKED_DEVICE"); | ||
expect(error.statusCode).toEqual(0x5515); | ||
}); | ||
test("transport status error contains message", () => { | ||
const error = new TransportStatusError(StatusCodes.UNKNOWN_APDU); | ||
expect(error.stack).toContain("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
@@ -60,2 +60,5 @@ import { serializeError, deserializeError, createCustomErrorClass, addCustomErrorDeserializer, LedgerErrorConstructor } from "./helpers"; | ||
}>; | ||
export declare const LockedDeviceError: LedgerErrorConstructor<{ | ||
[key: string]: unknown; | ||
}>; | ||
export declare const UnresponsiveDeviceError: LedgerErrorConstructor<{ | ||
@@ -346,3 +349,2 @@ [key: string]: unknown; | ||
}>; | ||
export type CustomErrorClassType = ReturnType<typeof createCustomErrorClass>; | ||
/** | ||
@@ -422,19 +424,6 @@ * Type of a Transport error used to represent all equivalent errors coming from all possible implementation of Transport | ||
*/ | ||
export declare class TransportStatusError extends Error { | ||
statusCode: number; | ||
statusText: string; | ||
/** | ||
* @param statusCode The error status code coming from a Transport implementation | ||
* @param options containing: | ||
* - canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it | ||
* . Ex: LockedDeviceError. Default to true. | ||
*/ | ||
constructor(statusCode: number, { canBeMappedToChildError }?: { | ||
canBeMappedToChildError?: boolean; | ||
}); | ||
export declare function TransportStatusError(statusCode: number): void; | ||
export declare namespace TransportStatusError { | ||
var prototype: Error; | ||
} | ||
export declare class LockedDeviceError extends TransportStatusError { | ||
constructor(message?: string); | ||
} | ||
export type TransportStatusErrorClassType = typeof TransportStatusError | typeof LockedDeviceError; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ManagerUninstallBTCDep = exports.ManagerNotEnoughSpaceError = exports.ManagerFirmwareNotEnoughSpaceError = exports.ManagerDeviceLockedError = exports.ManagerAppDepUninstallRequired = exports.ManagerAppDepInstallRequired = exports.ManagerAppRelyOnBTCError = exports.ManagerAppAlreadyInstalledError = exports.LedgerAPINotAvailable = exports.LedgerAPIErrorWithMessage = exports.LedgerAPIError = exports.UnknownMCU = exports.LatestMCUInstalledError = exports.InvalidAddressBecauseDestinationIsAlsoSource = exports.InvalidNonce = exports.InvalidAddress = exports.InvalidXRPTag = exports.HardResetFail = exports.FirmwareNotRecognized = exports.FeeEstimationFailed = exports.EthAppPleaseEnableContractData = exports.EnpointConfigError = exports.DeviceOnboardingStatePollingError = exports.DeviceExtractOnboardingStateError = exports.DisconnectedDeviceDuringOperation = exports.DisconnectedDevice = exports.UnresponsiveDeviceError = exports.DeviceSocketNoBulkStatus = exports.DeviceSocketFail = exports.DeviceNameInvalid = exports.DeviceHalted = exports.DeviceInOSUExpected = exports.DeviceOnDashboardUnexpected = exports.DeviceOnDashboardExpected = exports.DeviceNotGenuineError = exports.DeviceGenuineSocketEarlyClose = exports.DeviceAppVerifyNotSupported = exports.CurrencyNotSupported = exports.ClaimRewardsFeesWarning = exports.CashAddrNotSupported = exports.CantOpenDevice = exports.BtcUnmatchedApp = exports.BluetoothRequired = exports.AmountRequired = exports.AccountNotSupported = exports.AccountNameRequiredError = exports.addCustomErrorDeserializer = exports.createCustomErrorClass = exports.deserializeError = exports.serializeError = void 0; | ||
exports.FeeNotLoaded = exports.CantScanQRCode = exports.ETHAddressNonEIP = exports.WrongAppForCurrency = exports.WrongDeviceForAccount = exports.WebsocketConnectionFailed = exports.WebsocketConnectionError = exports.DeviceShouldStayInApp = exports.TransactionHasBeenValidatedError = exports.TransportWebUSBGestureRequired = exports.TransportRaceCondition = exports.TransportInterfaceNotAvailable = exports.TransportOpenUserCancelled = exports.ExpertModeRequired = exports.UserRefusedOnDevice = exports.UserRefusedAllowManager = exports.UserRefusedFirmwareUpdate = exports.UserRefusedAddress = exports.UserRefusedDeviceNameChange = exports.UpdateYourApp = exports.UpdateIncorrectSig = exports.UpdateIncorrectHash = exports.UpdateFetchFileFail = exports.UnavailableTezosOriginatedAccountSend = exports.UnavailableTezosOriginatedAccountReceive = exports.RecipientRequired = exports.MCUNotGenuineToDashboard = exports.UnexpectedBootloader = exports.TimeoutTagged = exports.RecommendUndelegation = exports.RecommendSubAccountsToEmpty = exports.PasswordIncorrectError = exports.PasswordsDontMatchError = exports.MaxFeeTooLow = exports.PriorityFeeHigherThanMaxFee = exports.PriorityFeeTooHigh = exports.PriorityFeeTooLow = exports.GasLessThanEstimate = exports.NotSupportedLegacyAddress = exports.NotEnoughGasSwap = exports.NotEnoughGas = exports.NoAccessToCamera = exports.NotEnoughBalanceBecauseDestinationNotCreated = exports.NotEnoughSpendableBalance = exports.NotEnoughBalanceInParentAccount = exports.NotEnoughBalanceToDelegate = exports.NotEnoughBalance = exports.NoAddressesFound = exports.NetworkError = exports.NetworkDown = void 0; | ||
exports.LockedDeviceError = exports.TransportStatusError = exports.getAltStatusMessage = exports.StatusCodes = exports.TransportError = exports.HwTransportError = exports.HwTransportErrorType = exports.DBNotReset = exports.DBWrongPassword = exports.NoDBPathGiven = exports.LanguageNotFound = exports.DustLimit = exports.OpReturnDataSizeLimit = exports.ReplacementTransactionUnderpriced = exports.FirmwareOrAppUpdateRequired = exports.LedgerAPI5xx = exports.LedgerAPI4xx = exports.GenuineCheckFailed = exports.PeerRemovedPairing = exports.PairingFailed = exports.SyncError = exports.PendingOperation = exports.FeeTooHigh = exports.FeeRequired = exports.FeeNotLoadedSwap = void 0; | ||
exports.ManagerNotEnoughSpaceError = exports.ManagerFirmwareNotEnoughSpaceError = exports.ManagerDeviceLockedError = exports.ManagerAppDepUninstallRequired = exports.ManagerAppDepInstallRequired = exports.ManagerAppRelyOnBTCError = exports.ManagerAppAlreadyInstalledError = exports.LedgerAPINotAvailable = exports.LedgerAPIErrorWithMessage = exports.LedgerAPIError = exports.UnknownMCU = exports.LatestMCUInstalledError = exports.InvalidAddressBecauseDestinationIsAlsoSource = exports.InvalidNonce = exports.InvalidAddress = exports.InvalidXRPTag = exports.HardResetFail = exports.FirmwareNotRecognized = exports.FeeEstimationFailed = exports.EthAppPleaseEnableContractData = exports.EnpointConfigError = exports.DeviceOnboardingStatePollingError = exports.DeviceExtractOnboardingStateError = exports.DisconnectedDeviceDuringOperation = exports.DisconnectedDevice = exports.UnresponsiveDeviceError = exports.LockedDeviceError = exports.DeviceSocketNoBulkStatus = exports.DeviceSocketFail = exports.DeviceNameInvalid = exports.DeviceHalted = exports.DeviceInOSUExpected = exports.DeviceOnDashboardUnexpected = exports.DeviceOnDashboardExpected = exports.DeviceNotGenuineError = exports.DeviceGenuineSocketEarlyClose = exports.DeviceAppVerifyNotSupported = exports.CurrencyNotSupported = exports.ClaimRewardsFeesWarning = exports.CashAddrNotSupported = exports.CantOpenDevice = exports.BtcUnmatchedApp = exports.BluetoothRequired = exports.AmountRequired = exports.AccountNotSupported = exports.AccountNameRequiredError = exports.addCustomErrorDeserializer = exports.createCustomErrorClass = exports.deserializeError = exports.serializeError = void 0; | ||
exports.CantScanQRCode = exports.ETHAddressNonEIP = exports.WrongAppForCurrency = exports.WrongDeviceForAccount = exports.WebsocketConnectionFailed = exports.WebsocketConnectionError = exports.DeviceShouldStayInApp = exports.TransactionHasBeenValidatedError = exports.TransportWebUSBGestureRequired = exports.TransportRaceCondition = exports.TransportInterfaceNotAvailable = exports.TransportOpenUserCancelled = exports.ExpertModeRequired = exports.UserRefusedOnDevice = exports.UserRefusedAllowManager = exports.UserRefusedFirmwareUpdate = exports.UserRefusedAddress = exports.UserRefusedDeviceNameChange = exports.UpdateYourApp = exports.UpdateIncorrectSig = exports.UpdateIncorrectHash = exports.UpdateFetchFileFail = exports.UnavailableTezosOriginatedAccountSend = exports.UnavailableTezosOriginatedAccountReceive = exports.RecipientRequired = exports.MCUNotGenuineToDashboard = exports.UnexpectedBootloader = exports.TimeoutTagged = exports.RecommendUndelegation = exports.RecommendSubAccountsToEmpty = exports.PasswordIncorrectError = exports.PasswordsDontMatchError = exports.MaxFeeTooLow = exports.PriorityFeeHigherThanMaxFee = exports.PriorityFeeTooHigh = exports.PriorityFeeTooLow = exports.GasLessThanEstimate = exports.NotSupportedLegacyAddress = exports.NotEnoughGasSwap = exports.NotEnoughGas = exports.NoAccessToCamera = exports.NotEnoughBalanceBecauseDestinationNotCreated = exports.NotEnoughSpendableBalance = exports.NotEnoughBalanceInParentAccount = exports.NotEnoughBalanceToDelegate = exports.NotEnoughBalance = exports.NoAddressesFound = exports.NetworkError = exports.NetworkDown = exports.ManagerUninstallBTCDep = void 0; | ||
exports.TransportStatusError = exports.getAltStatusMessage = exports.StatusCodes = exports.TransportError = exports.HwTransportError = exports.HwTransportErrorType = exports.DBNotReset = exports.DBWrongPassword = exports.NoDBPathGiven = exports.LanguageNotFound = exports.DustLimit = exports.OpReturnDataSizeLimit = exports.ReplacementTransactionUnderpriced = exports.FirmwareOrAppUpdateRequired = exports.LedgerAPI5xx = exports.LedgerAPI4xx = exports.GenuineCheckFailed = exports.PeerRemovedPairing = exports.PairingFailed = exports.SyncError = exports.PendingOperation = exports.FeeTooHigh = exports.FeeRequired = exports.FeeNotLoadedSwap = exports.FeeNotLoaded = void 0; | ||
const helpers_1 = require("./helpers"); | ||
@@ -30,2 +30,3 @@ Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return helpers_1.serializeError; } }); | ||
exports.DeviceSocketNoBulkStatus = (0, helpers_1.createCustomErrorClass)("DeviceSocketNoBulkStatus"); | ||
exports.LockedDeviceError = (0, helpers_1.createCustomErrorClass)("LockedDeviceError"); | ||
exports.UnresponsiveDeviceError = (0, helpers_1.createCustomErrorClass)("UnresponsiveDeviceError"); | ||
@@ -242,36 +243,20 @@ exports.DisconnectedDevice = (0, helpers_1.createCustomErrorClass)("DisconnectedDevice"); | ||
*/ | ||
class TransportStatusError extends Error { | ||
/** | ||
* @param statusCode The error status code coming from a Transport implementation | ||
* @param options containing: | ||
* - canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it | ||
* . Ex: LockedDeviceError. Default to true. | ||
*/ | ||
constructor(statusCode, { canBeMappedToChildError = true } = {}) { | ||
const statusText = Object.keys(exports.StatusCodes).find(k => exports.StatusCodes[k] === statusCode) || "UNKNOWN_ERROR"; | ||
const smsg = getAltStatusMessage(statusCode) || statusText; | ||
const statusCodeStr = statusCode.toString(16); | ||
const message = `Ledger device: ${smsg} (0x${statusCodeStr})`; | ||
super(message); | ||
this.name = "TransportStatusError"; | ||
this.statusCode = statusCode; | ||
this.statusText = statusText; | ||
// Maps to a LockedDeviceError | ||
if (canBeMappedToChildError && statusCode === exports.StatusCodes.LOCKED_DEVICE) { | ||
return new LockedDeviceError(message); | ||
} | ||
function TransportStatusError(statusCode) { | ||
const statusText = Object.keys(exports.StatusCodes).find(k => exports.StatusCodes[k] === statusCode) || "UNKNOWN_ERROR"; | ||
const smsg = getAltStatusMessage(statusCode) || statusText; | ||
const statusCodeStr = statusCode.toString(16); | ||
const message = `Ledger device: ${smsg} (0x${statusCodeStr})`; | ||
// Maps to a LockedDeviceError | ||
if (statusCode === exports.StatusCodes.LOCKED_DEVICE) { | ||
throw new exports.LockedDeviceError(message); | ||
} | ||
this.name = "TransportStatusError"; | ||
this.message = message; | ||
this.stack = new Error(message).stack; | ||
this.statusCode = statusCode; | ||
this.statusText = statusText; | ||
} | ||
exports.TransportStatusError = TransportStatusError; | ||
class LockedDeviceError extends TransportStatusError { | ||
constructor(message) { | ||
super(exports.StatusCodes.LOCKED_DEVICE, { canBeMappedToChildError: false }); | ||
if (message) { | ||
this.message = message; | ||
} | ||
this.name = "LockedDeviceError"; | ||
} | ||
} | ||
exports.LockedDeviceError = LockedDeviceError; | ||
TransportStatusError.prototype = new Error(); | ||
(0, helpers_1.addCustomErrorDeserializer)("TransportStatusError", e => new TransportStatusError(e.statusCode)); | ||
//# sourceMappingURL=index.js.map |
@@ -72,22 +72,7 @@ "use strict"; | ||
}); | ||
describe("TransportStatusError", () => { | ||
test("TransportStatusError contains the expected name, message, stack, status code and status message (non-regression)", () => { | ||
const error = new index_1.TransportStatusError(index_1.StatusCodes.UNKNOWN_APDU); | ||
console.log(`${JSON.stringify(error)}`); | ||
expect(error.name).toEqual("TransportStatusError"); | ||
expect(error.message).toEqual("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
expect(error.stack).toContain("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
expect(error.statusText).toEqual("UNKNOWN_APDU"); | ||
expect(error.statusCode).toEqual(0x6d02); | ||
}); | ||
test.only("TransportStatusError should be mapped to a LockedDeviceError on status code 0x5515", () => { | ||
const error = new index_1.TransportStatusError(index_1.StatusCodes.LOCKED_DEVICE); | ||
expect(error.name).toEqual("LockedDeviceError"); | ||
expect(error.message).toEqual("Ledger device: Locked device (0x5515)"); | ||
expect(error.stack).toContain("Ledger device: Locked device (0x5515)"); | ||
expect(error.statusText).toEqual("LOCKED_DEVICE"); | ||
expect(error.statusCode).toEqual(0x5515); | ||
}); | ||
test("transport status error contains message", () => { | ||
const error = new index_1.TransportStatusError(index_1.StatusCodes.UNKNOWN_APDU); | ||
expect(error.stack).toContain("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
{ | ||
"name": "@ledgerhq/errors", | ||
"version": "6.16.0-nightly.3", | ||
"version": "6.16.0", | ||
"description": "Ledger common errors", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -54,4 +54,2 @@ <img src="https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png" height="100" /> | ||
**Extends Error** | ||
Error thrown when a device returned a non success status. | ||
@@ -62,6 +60,4 @@ the error.statusCode is one of the `StatusCodes` exported by this library. | ||
* `statusCode` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The error status code coming from a Transport implementation | ||
* `options` **{canBeMappedToChildError: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?}** containing:* canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it | ||
. Ex: LockedDeviceError. Default to true. (optional, default `{}`) | ||
* `statusCode` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**  | ||
* `options.canBeMappedToChildError` (optional, default `true`) | ||
Returns **void**  |
@@ -76,25 +76,6 @@ import { AmountRequired, CurrencyNotSupported, TransportStatusError, StatusCodes } from "./index"; | ||
describe("TransportStatusError", () => { | ||
test("TransportStatusError contains the expected name, message, stack, status code and status message (non-regression)", () => { | ||
const error = new TransportStatusError(StatusCodes.UNKNOWN_APDU); | ||
console.log(`${JSON.stringify(error)}`); | ||
expect(error.name).toEqual("TransportStatusError"); | ||
expect(error.message).toEqual("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
expect(error.stack).toContain("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
expect(error.statusText).toEqual("UNKNOWN_APDU"); | ||
expect(error.statusCode).toEqual(0x6d02); | ||
}); | ||
test.only("TransportStatusError should be mapped to a LockedDeviceError on status code 0x5515", () => { | ||
const error = new TransportStatusError(StatusCodes.LOCKED_DEVICE); | ||
expect(error.name).toEqual("LockedDeviceError"); | ||
expect(error.message).toEqual("Ledger device: Locked device (0x5515)"); | ||
expect(error.stack).toContain("Ledger device: Locked device (0x5515)"); | ||
expect(error.statusText).toEqual("LOCKED_DEVICE"); | ||
expect(error.statusCode).toEqual(0x5515); | ||
}); | ||
test("transport status error contains message", () => { | ||
const error: Error = new TransportStatusError(StatusCodes.UNKNOWN_APDU); | ||
expect(error.stack).toContain("Ledger device: UNKNOWN_APDU (0x6d02)"); | ||
}); | ||
}); |
@@ -35,2 +35,3 @@ import { | ||
export const DeviceSocketNoBulkStatus = createCustomErrorClass("DeviceSocketNoBulkStatus"); | ||
export const LockedDeviceError = createCustomErrorClass("LockedDeviceError"); | ||
export const UnresponsiveDeviceError = createCustomErrorClass("UnresponsiveDeviceError"); | ||
@@ -172,5 +173,2 @@ export const DisconnectedDevice = createCustomErrorClass("DisconnectedDevice"); | ||
// Represents the type of all the classes created with createCustomErrorClass | ||
export type CustomErrorClassType = ReturnType<typeof createCustomErrorClass>; | ||
/** | ||
@@ -293,48 +291,22 @@ * Type of a Transport error used to represent all equivalent errors coming from all possible implementation of Transport | ||
*/ | ||
export class TransportStatusError extends Error { | ||
statusCode: number; | ||
statusText: string; | ||
export function TransportStatusError(statusCode: number): void { | ||
const statusText = | ||
Object.keys(StatusCodes).find(k => StatusCodes[k] === statusCode) || "UNKNOWN_ERROR"; | ||
const smsg = getAltStatusMessage(statusCode) || statusText; | ||
const statusCodeStr = statusCode.toString(16); | ||
const message = `Ledger device: ${smsg} (0x${statusCodeStr})`; | ||
/** | ||
* @param statusCode The error status code coming from a Transport implementation | ||
* @param options containing: | ||
* - canBeMappedToChildError: enable the mapping of TransportStatusError to an error extending/inheriting from it | ||
* . Ex: LockedDeviceError. Default to true. | ||
*/ | ||
constructor( | ||
statusCode: number, | ||
{ canBeMappedToChildError = true }: { canBeMappedToChildError?: boolean } = {}, | ||
) { | ||
const statusText = | ||
Object.keys(StatusCodes).find(k => StatusCodes[k] === statusCode) || "UNKNOWN_ERROR"; | ||
const smsg = getAltStatusMessage(statusCode) || statusText; | ||
const statusCodeStr = statusCode.toString(16); | ||
const message = `Ledger device: ${smsg} (0x${statusCodeStr})`; | ||
super(message); | ||
this.name = "TransportStatusError"; | ||
this.statusCode = statusCode; | ||
this.statusText = statusText; | ||
// Maps to a LockedDeviceError | ||
if (canBeMappedToChildError && statusCode === StatusCodes.LOCKED_DEVICE) { | ||
return new LockedDeviceError(message); | ||
} | ||
// Maps to a LockedDeviceError | ||
if (statusCode === StatusCodes.LOCKED_DEVICE) { | ||
throw new LockedDeviceError(message); | ||
} | ||
} | ||
export class LockedDeviceError extends TransportStatusError { | ||
constructor(message?: string) { | ||
super(StatusCodes.LOCKED_DEVICE, { canBeMappedToChildError: false }); | ||
if (message) { | ||
this.message = message; | ||
} | ||
this.name = "LockedDeviceError"; | ||
} | ||
this.name = "TransportStatusError"; | ||
this.message = message; | ||
this.stack = new Error(message).stack; | ||
this.statusCode = statusCode; | ||
this.statusText = statusText; | ||
} | ||
TransportStatusError.prototype = new Error(); | ||
// Represents the type of the class TransportStatusError and its children | ||
export type TransportStatusErrorClassType = typeof TransportStatusError | typeof LockedDeviceError; | ||
addCustomErrorDeserializer("TransportStatusError", e => new TransportStatusError(e.statusCode)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
0
173552
43
2492
62