From 63e408f4f2c3886874fb8a6cbd9e10a5ee6bd33a Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Sat, 1 Oct 2022 15:42:34 +0100 Subject: [PATCH 1/2] Fixed octopush legacy doesn't return error code The octopush legacy API does not return a HTTP error code and instead always returns a HTTP 200. This means that no error it thrown even if something like the parameters are incorrect. Instead the error code is given in the json response data. Therefore we must look at the response data and check for the presence of the "error_code" key in the response data. Signed-off-by: Matthew Nickson --- server/notification-providers/octopush.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/notification-providers/octopush.js b/server/notification-providers/octopush.js index 524a4a880..35d88f5f3 100644 --- a/server/notification-providers/octopush.js +++ b/server/notification-providers/octopush.js @@ -49,7 +49,13 @@ class Octopush extends NotificationProvider { }, params: data }; - await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config); + + // V1 API returns 200 even on error so we must check + // response data + let response = await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config); + if ("error_code" in response.data) { + this.throwGeneralAxiosError(`Octopush error ${JSON.stringify(response.data)}`); + } } else { throw new Error("Unknown Octopush version!"); } From 97de3959cd3c71d17bcfa32a2a3ec131c3255e9b Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Sat, 1 Oct 2022 19:48:00 +0100 Subject: [PATCH 2/2] Updated octopush error handling to accept 000 The legacy octopush API includes an error code with all responses. A code other than 000 is an error. Signed-off-by: Matthew Nickson --- server/notification-providers/octopush.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/notification-providers/octopush.js b/server/notification-providers/octopush.js index 35d88f5f3..d5c475d3d 100644 --- a/server/notification-providers/octopush.js +++ b/server/notification-providers/octopush.js @@ -54,7 +54,9 @@ class Octopush extends NotificationProvider { // response data let response = await axios.post("https://www.octopush-dm.com/api/sms/json", {}, config); if ("error_code" in response.data) { - this.throwGeneralAxiosError(`Octopush error ${JSON.stringify(response.data)}`); + if (response.data.error_code !== "000") { + this.throwGeneralAxiosError(`Octopush error ${JSON.stringify(response.data)}`); + } } } else { throw new Error("Unknown Octopush version!");