From 799316fe3ec776be4239c7562a40bada3bdd9332 Mon Sep 17 00:00:00 2001 From: zhzoo Date: Thu, 11 Jan 2018 11:52:57 -0800 Subject: [PATCH 1/4] not found / active constant --- node/lib/OpenT2TConstants.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/node/lib/OpenT2TConstants.ts b/node/lib/OpenT2TConstants.ts index 51bd19e..e5222ef 100644 --- a/node/lib/OpenT2TConstants.ts +++ b/node/lib/OpenT2TConstants.ts @@ -17,6 +17,7 @@ export class OpenT2TConstants { public static MissingTranslator: string = "Cannot find translator module"; public static MustSubscribeToDevice: string = "Must subscribe to a device"; public static NotImplemented: string = "Not Implemented"; + public static NotFoundOrActive: string = "Device not found or active"; public static ResourceNotFound: string = "Resource not found"; public static UnknownHubSubscribeRequest: string = "Unknown subscription request"; public static UnknownPlatform: string = "Unknown platform. The requested platform cannot be translated"; From 1bc2f9c722c9c9cfcafc3fb2431bdf872e17d821 Mon Sep 17 00:00:00 2001 From: zhzoo Date: Thu, 11 Jan 2018 12:05:34 -0800 Subject: [PATCH 2/4] more descriptive --- node/lib/OpenT2TConstants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/lib/OpenT2TConstants.ts b/node/lib/OpenT2TConstants.ts index e5222ef..54a0baf 100644 --- a/node/lib/OpenT2TConstants.ts +++ b/node/lib/OpenT2TConstants.ts @@ -17,7 +17,7 @@ export class OpenT2TConstants { public static MissingTranslator: string = "Cannot find translator module"; public static MustSubscribeToDevice: string = "Must subscribe to a device"; public static NotImplemented: string = "Not Implemented"; - public static NotFoundOrActive: string = "Device not found or active"; + public static NotFoundOrActive: string = "Device not found or unreachable"; public static ResourceNotFound: string = "Resource not found"; public static UnknownHubSubscribeRequest: string = "Unknown subscription request"; public static UnknownPlatform: string = "Unknown platform. The requested platform cannot be translated"; From 3acb045afca9e889773407e65ddd48d75055272f Mon Sep 17 00:00:00 2001 From: zhzoo Date: Thu, 11 Jan 2018 12:07:58 -0800 Subject: [PATCH 3/4] name change --- node/lib/OpenT2TConstants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/lib/OpenT2TConstants.ts b/node/lib/OpenT2TConstants.ts index 54a0baf..50b5064 100644 --- a/node/lib/OpenT2TConstants.ts +++ b/node/lib/OpenT2TConstants.ts @@ -17,7 +17,7 @@ export class OpenT2TConstants { public static MissingTranslator: string = "Cannot find translator module"; public static MustSubscribeToDevice: string = "Must subscribe to a device"; public static NotImplemented: string = "Not Implemented"; - public static NotFoundOrActive: string = "Device not found or unreachable"; + public static Unreachable: string = "Device not found or unreachable"; public static ResourceNotFound: string = "Resource not found"; public static UnknownHubSubscribeRequest: string = "Unknown subscription request"; public static UnknownPlatform: string = "Unknown platform. The requested platform cannot be translated"; From 715b383072c5154a56074df2c3e18982db996a85 Mon Sep 17 00:00:00 2001 From: Ellen Porter Date: Fri, 9 Feb 2018 13:19:10 -0800 Subject: [PATCH 4/4] Updating error constants --- node/lib/OpenT2TConstants.ts | 13 ++++++------ node/lib/OpenT2TError.ts | 39 +++++++++++++++++++++++++++++++++++- node/lib/OpenT2TErrorData.ts | 14 +++++++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 node/lib/OpenT2TErrorData.ts diff --git a/node/lib/OpenT2TConstants.ts b/node/lib/OpenT2TConstants.ts index 50b5064..6d5e799 100644 --- a/node/lib/OpenT2TConstants.ts +++ b/node/lib/OpenT2TConstants.ts @@ -4,20 +4,21 @@ */ export class OpenT2TConstants { // Errors - public static InternalServerError: string = - "Unexpected error. Please retry the operation or contact OpenT2T support"; - + public static InternalServerError: string = "Unexpected error. Please retry the operation or contact OpenT2T support"; public static AccessDenied: string = "Access denied"; public static DeviceNotFound: string = "Device not found"; public static HMacSignatureVerificationFailed: string = "Payload signature doesn't match"; - public static InvalidAuthInfoInput: string = - "Invalid authInfo object. Please provide the existing authInfo object"; + public static InvalidAuthInfoInput: string = "Invalid authInfo object. Please provide the existing authInfo object"; + public static ExpiredAuthToken: string = "Expired authentication token"; public static InvalidHubId: string = "Invalid hub id"; public static InvalidResourceId: string = "Invalid resourceId"; + public static InvalidResource: string = "Invalid resource"; public static MissingTranslator: string = "Cannot find translator module"; public static MustSubscribeToDevice: string = "Must subscribe to a device"; public static NotImplemented: string = "Not Implemented"; - public static Unreachable: string = "Device not found or unreachable"; + public static Unreachable: string = "Device is unreachable"; + public static DeviceOff: string = "Device is off"; + public static RangeCheck: string = "Range check failed"; public static ResourceNotFound: string = "Resource not found"; public static UnknownHubSubscribeRequest: string = "Unknown subscription request"; public static UnknownPlatform: string = "Unknown platform. The requested platform cannot be translated"; diff --git a/node/lib/OpenT2TError.ts b/node/lib/OpenT2TError.ts index dbdc2c0..9969d43 100644 --- a/node/lib/OpenT2TError.ts +++ b/node/lib/OpenT2TError.ts @@ -1,4 +1,5 @@ import { OpenT2TConstants } from "./OpenT2TConstants"; +import { OpenT2TErrorData } from "./OpenT2TErrorData"; /** * Custom Error class that extends built-in Error. @@ -7,11 +8,47 @@ export class OpenT2TError extends Error { public statusCode: number; public innerError: Error; - constructor(statusCode: number, message: string, innerError?: Error) { + constructor(statusCode: number, message: string, innerError?: Error, data?: OpenT2TErrorData) { if (!message) { message = OpenT2TConstants.InternalServerError; } + //**** Format the message if the user provided data */ + // Bad request + if (data !== undefined && data !== null) { + if (statusCode == 400) { + // Invalid resource + if (message === OpenT2TConstants.InvalidResource) { + message = data.provider + ": " + message + " found " + data.attributeId + " '" + data.value + "'"; + if(data.expected) { + message += "; expected " + data.expected; + } + } + } + if (statusCode == 401) { + // Unauthorized + if (message === OpenT2TConstants.AccessDenied) { + message = data.provider + ": " + message; + if(data.details) { + message += "; " + data.details; + } + } + } + if (statusCode == 440) { + // Value outside range + if (message === OpenT2TConstants.RangeCheck) { + message = data.provider + ": " + message + " found " + data.attributeId + " '" + data.value + + " " + data.unit + "'; expected [" + data.min + ", " + data.max + "]"; + } + } + if (statusCode == 442) { + // Device is off + if (message === OpenT2TConstants.DeviceOff) { + message = data.provider + ": " + message; + } + } + } + super(message); // Set the prototype explicitly due to TS breaking change. diff --git a/node/lib/OpenT2TErrorData.ts b/node/lib/OpenT2TErrorData.ts new file mode 100644 index 0000000..b62065c --- /dev/null +++ b/node/lib/OpenT2TErrorData.ts @@ -0,0 +1,14 @@ +export class OpenT2TErrorData { + + public provider: string; + public attributeId: string; + public value: string; + public unit: string; + + public min: number; + public max: number; + + public expected: string; + public details: string; + +} \ No newline at end of file