11import * as HelpDoc from "@effect/cli/HelpDoc" ;
22import type { ValidationError as EffectValidationError } from "@effect/cli/ValidationError" ;
3- import { type CliError , errorCode } from "../../effect/errors" ;
3+ import {
4+ type ApiErrorContext ,
5+ type CliError ,
6+ errorCode ,
7+ } from "../../effect/errors" ;
48
59export interface AgentErrorDetails {
610 message : string ;
711 code : string ;
812 fix : string ;
13+ details ?: Record < string , unknown > ;
914}
1015
1116const ANSI_ESCAPE_PATTERN = new RegExp (
@@ -28,9 +33,52 @@ function formatValidationMessage(error: EffectValidationError): string {
2833 return "Invalid command input" ;
2934}
3035
36+ function apiDetails ( error : CliError ) : Record < string , unknown > | undefined {
37+ const context = error as Partial < ApiErrorContext > ;
38+
39+ const details : Record < string , unknown > = { } ;
40+ if ( typeof context . status === "number" ) {
41+ details . status = context . status ;
42+ }
43+ if ( typeof context . statusText === "string" && context . statusText . length > 0 ) {
44+ details . status_text = context . statusText ;
45+ }
46+ if ( typeof context . endpoint === "string" && context . endpoint . length > 0 ) {
47+ details . endpoint = context . endpoint ;
48+ }
49+ if ( typeof context . method === "string" && context . method . length > 0 ) {
50+ details . method = context . method ;
51+ }
52+ if ( typeof context . requestId === "string" && context . requestId . length > 0 ) {
53+ details . request_id = context . requestId ;
54+ }
55+ if ( context . responseBody !== undefined ) {
56+ details . response = context . responseBody ;
57+ }
58+
59+ return Object . keys ( details ) . length > 0 ? details : undefined ;
60+ }
61+
62+ function fixForNetworkError (
63+ details : Record < string , unknown > | undefined ,
64+ ) : string {
65+ const status = details ?. status ;
66+ if ( typeof status === "number" ) {
67+ if ( status >= 400 && status < 500 ) {
68+ return "Check request path/query/body. Inspect error.details.response for API validation feedback." ;
69+ }
70+ if ( status >= 500 ) {
71+ return "The API is currently failing server-side. Retry, or check service health/incidents." ;
72+ }
73+ }
74+
75+ return "Verify environment connectivity with: godaddy env get and retry." ;
76+ }
77+
3178function fromTaggedError ( error : CliError ) : AgentErrorDetails {
3279 const code = errorCode ( error ) ;
3380 const message = error . userMessage || error . message ;
81+ const details = apiDetails ( error ) ;
3482
3583 switch ( error . _tag ) {
3684 case "ValidationError" :
@@ -44,6 +92,7 @@ function fromTaggedError(error: CliError): AgentErrorDetails {
4492 message,
4593 code : "AUTH_REQUIRED" ,
4694 fix : "Run: godaddy auth login" ,
95+ details,
4796 } ;
4897 case "ConfigurationError" :
4998 return {
@@ -55,7 +104,8 @@ function fromTaggedError(error: CliError): AgentErrorDetails {
55104 return {
56105 message,
57106 code,
58- fix : "Verify environment connectivity with: godaddy env get and retry." ,
107+ fix : fixForNetworkError ( details ) ,
108+ details,
59109 } ;
60110 case "SecurityError" :
61111 return {
0 commit comments