Update isWithCode - allow string code

This commit is contained in:
Dmitry Leleko
2023-01-23 16:33:37 +03:00
parent 530edc3b46
commit edddd6c5c3
2 changed files with 5 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.16.0-rc.23",
"version": "0.16.0-rc.24",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -3,7 +3,7 @@ type WithReason = {
}
type WithCodeError = Error & {
code: number;
code: number | string;
}
type WithMessage = {
@@ -41,9 +41,9 @@ export function hasProp<T extends Record<string, unknown>, K extends PropertyKey
}
export function isWithCode(candidate: unknown): candidate is WithCodeError {
if (!isUnknownObject(candidate)) return false;
const hasCodeProperty = hasProp(candidate, 'code') && typeof candidate.code === 'number';
return hasCodeProperty;
if (!isUnknownObject(candidate) || !hasProp(candidate, 'code')) return false;
const type = typeof candidate.code;
return type === 'number' || type === 'string';
}
export function isWithReason(candidate: unknown): candidate is WithReason {