axios+telemetry cleanup
This commit is contained in:
@@ -194,43 +194,33 @@ export function isFsInaccessible(e: unknown): e is NodeJS.ErrnoException {
|
||||
)
|
||||
}
|
||||
|
||||
export type AxiosErrorKind =
|
||||
export type HttpErrorKind =
|
||||
| 'auth' // 401/403 — caller typically sets skipRetry
|
||||
| 'timeout' // ECONNABORTED
|
||||
| 'timeout' // 408 or ECONNABORTED
|
||||
| 'network' // ECONNREFUSED/ENOTFOUND
|
||||
| 'http' // other axios error (may have status)
|
||||
| 'other' // not an axios error
|
||||
| 'http' // other http error (may have status)
|
||||
| 'other' // not an http error
|
||||
|
||||
/**
|
||||
* Classify a caught error from an axios request into one of a few buckets.
|
||||
* Replaces the ~20-line isAxiosError → 401/403 → ECONNABORTED → ECONNREFUSED
|
||||
* chain duplicated across sync-style services (settingsSync, policyLimits,
|
||||
* remoteManagedSettings, teamMemorySync).
|
||||
*
|
||||
* Checks the `.isAxiosError` marker property directly (same as
|
||||
* axios.isAxiosError()) to keep this module dependency-free.
|
||||
* Classify a caught error from a request into one of a few buckets.
|
||||
*/
|
||||
export function classifyAxiosError(e: unknown): {
|
||||
kind: AxiosErrorKind
|
||||
export function classifyHttpError(e: unknown): {
|
||||
kind: HttpErrorKind
|
||||
status?: number
|
||||
message: string
|
||||
} {
|
||||
const message = errorMessage(e)
|
||||
if (
|
||||
!e ||
|
||||
typeof e !== 'object' ||
|
||||
!('isAxiosError' in e) ||
|
||||
!e.isAxiosError
|
||||
) {
|
||||
if (!e || typeof e !== 'object' || !('name' in e) || e.name !== 'HttpError') {
|
||||
return { kind: 'other', message }
|
||||
}
|
||||
const err = e as {
|
||||
response?: { status?: number }
|
||||
status?: number
|
||||
code?: string
|
||||
}
|
||||
const status = err.response?.status
|
||||
const status = err.status
|
||||
if (status === 401 || status === 403) return { kind: 'auth', status, message }
|
||||
if (err.code === 'ECONNABORTED') return { kind: 'timeout', status, message }
|
||||
if (status === 408 || err.code === 'ECONNABORTED')
|
||||
return { kind: 'timeout', status, message }
|
||||
if (err.code === 'ECONNREFUSED' || err.code === 'ENOTFOUND') {
|
||||
return { kind: 'network', status, message }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user