* 读取响应体 * @param {Response} response - Fetch 响应对象 * @returns {Promise<*>} 响应体
(response)
| 41 | * @returns {Promise<*>} 响应体 |
| 42 | */ |
| 43 | async readResponseBody(response) { |
| 44 | const contentType = response.headers.get('content-type') || '' |
| 45 | const rawText = await response.text() |
| 46 | |
| 47 | if (!rawText) { |
| 48 | return '' |
| 49 | } |
| 50 | |
| 51 | if (contentType.includes('application/json')) { |
| 52 | try { |
| 53 | return JSON.parse(rawText) |
| 54 | } catch (error) { |
| 55 | return rawText |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return rawText |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * 启动 OAuth 设备授权流程 |
no outgoing calls
no test coverage detected