diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 154c5e87a..d027418d1 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -7,6 +7,8 @@ > Users must be able to say: “Nice enhancement, I'm eager to test it” +- [Netbox] Add information about a failed request to the error log to help better understand what happened [#5834](https://github.com/vatesfr/xen-orchestra/issues/5834) (PR [#5842](https://github.com/vatesfr/xen-orchestra/pull/5842)) + ### Bug fixes > Users must be able to say: “I had this issue, happy to know it's fixed” @@ -27,3 +29,5 @@ > - major: if the change breaks compatibility > > In case of conflict, the highest (lowest in previous list) `$version` wins. + +- xo-server-netbox minor diff --git a/packages/xo-server-netbox/src/index.js b/packages/xo-server-netbox/src/index.js index 03404d049..f58cb986a 100644 --- a/packages/xo-server-netbox/src/index.js +++ b/packages/xo-server-netbox/src/index.js @@ -97,10 +97,9 @@ class Netbox { } async #makeRequest(path, method, data) { - log.debug( - `${method} ${path}`, + const dataDebug = Array.isArray(data) && data.length > 2 ? [...data.slice(0, 2), `and ${data.length - 2} others`] : data - ) + log.debug(`${method} ${path}`, dataDebug) let url = this.#endpoint + '/api' + path const options = { headers: { 'Content-Type': 'application/json', Authorization: `Token ${this.#token}` }, @@ -116,10 +115,15 @@ class Netbox { return JSON.parse(body) } } catch (error) { + error.data = { + method, + path, + body: dataDebug, + } try { const body = await error.response.readAll() if (body.length > 0) { - log.error(body.toString()) + error.data.error = JSON.parse(body) } } catch { throw error