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 <mnickson@sidingsmedia.com>
This commit is contained in:
Matthew Nickson 2022-10-01 15:42:34 +01:00
parent 2e54dee817
commit 63e408f4f2
No known key found for this signature in database
GPG Key ID: BF229DCFD4748E05
1 changed files with 7 additions and 1 deletions

View File

@ -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!");
}