[kfetch/FetchError] only call Error.captureStackTrace if it exists (#21376)

* [kfetch/FetchError] only call Error.captureStackTrace if it exists

* add comment for clarity [skip ci]
This commit is contained in:
Spencer 2018-07-30 12:32:39 -07:00 committed by GitHub
parent 7063dbcbd9
commit f0140850db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,7 +28,12 @@ import { metadata } from '../metadata';
class FetchError extends Error {
constructor(public readonly res: Response, public readonly body?: any) {
super(res.statusText);
Error.captureStackTrace(this, FetchError);
// captureStackTrace is only available in the V8 engine, so any browser using
// a different JS engine won't have access to this method.
if (Error.captureStackTrace) {
Error.captureStackTrace(this, FetchError);
}
}
}