Esri / arcgis-rest-js

compact, modular JavaScript wrappers for the ArcGIS REST API
https://developers.arcgis.com/arcgis-rest-js/
Apache License 2.0
354 stars 119 forks source link

Expose Response Headers on ArcgisError object for status != 200 #1181

Open efbenson opened 1 week ago

efbenson commented 1 week ago

Describe the problem

We had a support request with AGOL and they need the response headers, there is no way to get them from this package without patching the module (which we are attempting) When a status code 500/503 (non 200) error is returned the response headers are not exposed via the error object.

Describe the proposed solution

We are seeing if this will work (in my simulations it appeared to). Tweaking this code here seemed to do it.

https://github.com/Esri/arcgis-rest-js/blob/main/packages/arcgis-rest-request/src/request.ts#L424

            const { status, statusText, headers } = response;
            const { message, details } = jsonError.error;
            const formattedMessage = `${message}. ${
              details ? details.join(" ") : ""
            }`.trim();

            throw new ArcGISRequestError(
              formattedMessage,
              `HTTP ${status} ${statusText}`,
              {body: jsonError, headers: [...headers]},
              url,
              options
            );
          })

Alternatives considered

No response

Additional Information

No response

gavinr-maps commented 1 week ago

@efbenson thank you for logging this issue. This request seems reasonable to me. @patrickarlt @dbouwman do you have any thoughts on this request? Just to be clear, the proposed change is to change/add this code:

image ... at this location: https://github.com/Esri/arcgis-rest-js/blob/main/packages/arcgis-rest-request/src/request.ts#L424

patrickarlt commented 6 days ago

This looks good do me if someone wants to do a PR.