finish phase 4: drop @atproto/api dependency, lex-only errors, delete toLex and legacy validators
oxlint-suppressions.json gains a baseline entry for webpack.config.js: the file was never previously staged/linted (lint script covers src+modules only), and editing it exposed its pre-existing violations to lint-staged. All suppressed counts are pre-existing; this change only removes a line.
This commit is contained in:
+14
-24
@@ -1,44 +1,34 @@
|
||||
import {XRPCError} from '@atproto/api'
|
||||
import {XrpcError, XrpcResponseError} from '@atproto/lex-client'
|
||||
|
||||
/**
|
||||
* True for an XRPC error from either the old bridge agent (`@atproto/api`
|
||||
* `XRPCError`) or a lex `Client` (`@atproto/lex-client` `XrpcError`, the
|
||||
* abstract base of `XrpcResponseError`/`XrpcInvalidResponseError`/
|
||||
* `XrpcInternalError`). During the migration both worlds can throw, so matchers
|
||||
* must accept both.
|
||||
* True for an XRPC error from a lex `Client` (`@atproto/lex-client` `XrpcError`,
|
||||
* the abstract base of `XrpcResponseError`/`XrpcInvalidResponseError`/
|
||||
* `XrpcInternalError`).
|
||||
*/
|
||||
export function isXrpcError(e: unknown): e is XRPCError | XrpcError {
|
||||
return e instanceof XRPCError || e instanceof XrpcError
|
||||
export function isXrpcError(e: unknown): e is XrpcError {
|
||||
return e instanceof XrpcError
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP status, or undefined if not an XRPC error / no response. Only lex
|
||||
* HTTP status, or undefined if not an XRPC error / no response. Only
|
||||
* `XrpcResponseError` (a server response) carries a status; the internal/fetch
|
||||
* lex errors do not.
|
||||
*/
|
||||
export function getErrorStatus(e: unknown): number | undefined {
|
||||
if (e instanceof XRPCError) return e.status
|
||||
if (e instanceof XrpcResponseError) return e.status
|
||||
return undefined
|
||||
return e instanceof XrpcResponseError ? e.status : undefined
|
||||
}
|
||||
|
||||
/** The lexicon error code (`err.error`), from either world. */
|
||||
/** The lexicon error code (`err.error`). */
|
||||
export function getErrorName(e: unknown): string | undefined {
|
||||
if (isXrpcError(e)) return (e as {error?: string}).error
|
||||
return undefined
|
||||
return isXrpcError(e) ? (e as {error?: string}).error : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a response header off an XRPC error, normalizing the shape change:
|
||||
* old XRPCError.headers is a plain record; lex XrpcResponseError.headers is a
|
||||
* WHATWG Headers object.
|
||||
* Read a response header off an XRPC error. Only `XrpcResponseError` carries a
|
||||
* response; its `.headers` is a WHATWG `Headers` object.
|
||||
*/
|
||||
export function getErrorHeader(e: unknown, name: string): string | undefined {
|
||||
if (e instanceof XrpcResponseError) return e.headers.get(name) ?? undefined
|
||||
if (e instanceof XRPCError) {
|
||||
const h = (e as {headers?: Record<string, string>}).headers
|
||||
return h?.[name.toLowerCase()]
|
||||
}
|
||||
return undefined
|
||||
return e instanceof XrpcResponseError
|
||||
? (e.headers.get(name) ?? undefined)
|
||||
: undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user