* Checks the response of an operation. Throws if there's an error, and prints * success messages if not. * @param {!Response} response * @param {...string} successMessages * @return {Promise }
(response, ...successMessages)
| 63 | * @return {Promise<void>} |
| 64 | */ |
| 65 | async function checkResponse(response, ...successMessages) { |
| 66 | if (!response.ok) { |
| 67 | throw new Error( |
| 68 | `${response.status} ${response.statusText}: ${await response.text()}` |
| 69 | ); |
| 70 | } else { |
| 71 | log(...successMessages); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Does a JSON POST request. |
no test coverage detected