GoogleCloudPlatform / stackdriver-errors-js

Client-side JavaScript exception reporting library for Cloud Error Reporting
https://cloud.google.com/error-reporting/
Apache License 2.0
362 stars 54 forks source link

report() should allow handling of non-200 Stackdriver responses #32

Closed calbach closed 5 years ago

calbach commented 6 years ago

Current API signature:

report(e, callback), where callback happens on both success or failure (passed XHR error on transaction failure).

In the event that the Stackdriver XHR succeeds with a non-200, e.g. 403 due to API key origin restriction, callback is invoked without parameters, so it looks like a success to the client. This is because XMLHttpRequest.onerror is not dependent on the HTTP status code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget/onerror

Relevant code: https://github.com/GoogleCloudPlatform/stackdriver-errors-js/blob/f549a50048f424768d819eb36784817e86c13a2a/stackdriver-errors.js#L146

Possibly this method could be changed to accept two callbacks, or else use a Promise. The error path should trigger if the HTTP response status is not a 200.