Skip to content

Commit

Permalink
feat(service): ✨ http错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
Aybrea committed Jan 14, 2025
1 parent 16c4dea commit 9d86906
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/services/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ async function Http<T = any>(
return { data: responseData, resp: response }
}
return responseData
} catch (err) {
console.error(`Attempt ${currentAttempt + 1} failed →`, err)
} catch (error) {
console.error(`Attempt ${currentAttempt + 1} failed →`, error)

Check warning on line 168 in src/services/http.ts

View check run for this annotation

Codecov / codecov/patch

src/services/http.ts#L167-L168

Added lines #L167 - L168 were not covered by tests

// 检查是否仍需重试
if (!shouldRetry(currentAttempt, retries, abort)) {
console.error(`Max retries reached or aborted. Request failed → ${url}`)
throw err instanceof Error ? err : new Error(String(err)) // 不再重试,抛出最终错误
const finalError = error instanceof FetchRetryError ? error : new Error(String(error))
window.$message?.error(finalError.message)
throw finalError // 不再重试,抛出最终错误

Check warning on line 175 in src/services/http.ts

View check run for this annotation

Codecov / codecov/patch

src/services/http.ts#L173-L175

Added lines #L173 - L175 were not covered by tests
}

// 若需继续重试
Expand Down

0 comments on commit 9d86906

Please sign in to comment.