MCPcopy Create free account
hub / github.com/IIIIQIIII/claude-code / classifyAPIError

Function classifyAPIError

src/services/api/errors.ts:963–1159  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

961 * Returns a standardized error type string suitable for Datadog tagging.
962 */
963export function classifyAPIError(error: unknown): string {
964 // Aborted requests
965 if (error instanceof Error && error.message === 'Request was aborted.') {
966 return 'aborted'
967 }
968
969 // Timeout errors
970 if (
971 error instanceof APIConnectionTimeoutError ||
972 (error instanceof APIConnectionError &&
973 error.message.toLowerCase().includes('timeout'))
974 ) {
975 return 'api_timeout'
976 }
977
978 // Check for repeated 529 errors
979 if (
980 error instanceof Error &&
981 error.message.includes(REPEATED_529_ERROR_MESSAGE)
982 ) {
983 return 'repeated_529'
984 }
985
986 // Check for emergency capacity off switch
987 if (
988 error instanceof Error &&
989 error.message.includes(CUSTOM_OFF_SWITCH_MESSAGE)
990 ) {
991 return 'capacity_off_switch'
992 }
993
994 // Rate limiting
995 if (error instanceof APIError && error.status === 429) {
996 return 'rate_limit'
997 }
998
999 // Server overload (529)
1000 if (
1001 error instanceof APIError &&
1002 (error.status === 529 ||
1003 error.message?.includes('"type":"overloaded_error"'))
1004 ) {
1005 return 'server_overload'
1006 }
1007
1008 // Prompt/content size errors
1009 if (
1010 error instanceof Error &&
1011 error.message
1012 .toLowerCase()
1013 .includes(PROMPT_TOO_LONG_ERROR_MESSAGE.toLowerCase())
1014 ) {
1015 return 'prompt_too_long'
1016 }
1017
1018 // PDF errors
1019 if (
1020 error instanceof Error &&

Callers 1

logAPIErrorFunction · 0.85

Calls 2

isEnvTruthyFunction · 0.85

Tested by

no test coverage detected