* Returns the response if successful or otherwise throws an error. * @param {!FetchResponse} response * @return {!Promise<!FetchResponse>} * @private Visible for testing
(response)
| 13585 | * @private Visible for testing |
| 13586 | */ |
| 13587 | function assertSuccess(response) { |
| 13588 | return new Promise((resolve) => { |
| 13589 | if (response.ok) { |
| 13590 | return resolve(response); |
| 13591 | } |
| 13592 | |
| 13593 | const {status} = response; |
| 13594 | const err = new Error(`HTTP error ${status}`); |
| 13595 | err.retriable = isRetriable(status); |
| 13596 | // TODO(@jridgewell, #9448): Callers who need the response should |
| 13597 | // skip processing. |
| 13598 | err.response = response; |
| 13599 | throw err; |
| 13600 | }); |
| 13601 | } |
| 13602 | |
| 13603 | /** |
| 13604 | * Response object in the Fetch API. |
no test coverage detected