Skip to content

Commit

Permalink
Fix nested array data on Monitor.put
Browse files Browse the repository at this point in the history
Make sure the `data` param is only reassigned into an array if the
initial `data` param is not an array.

> In the method `Monitor.put`, the assertion `typeof data == 'object'` returns
> `true` whether `data` is an Array or not. This causes `data` to be reassigned
> as a nested array when `Monitor.put` is called with an array as the
> `data` parameter, resulting in an HTTP 500 Error from the API.
  • Loading branch information
alexpresthus committed Apr 18, 2024
1 parent f5b0207 commit b5f4522
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class Monitor {

static async put(data, rollback = false) {
if (typeof data == 'object') {
data = [data];
if (!Array.isArray(data)) {
data = [data];
}
} else {
throw new Errors.MonitorNotCreated('Invalid monitor data.');
}
Expand Down Expand Up @@ -125,4 +127,4 @@ class Monitor {
}

module.exports = Monitor;
module.exports.default = Monitor;
module.exports.default = Monitor;

0 comments on commit b5f4522

Please sign in to comment.