11import axios from "axios"
22import { jwtDecode } from "jwt-decode"
33import crypto from "crypto"
4+ import retry from "async-retry"
45
56import { t } from "../../../i18n"
67import { ClineProvider } from "../../webview/ClineProvider"
@@ -47,12 +48,22 @@ export class ErrorCodeManager {
4748 */
4849 public async refreshErrorCodes ( ) : Promise < void > {
4950 try {
50- // Clear existing error code mapping
51- this . errorMap = { }
52- // Get remote error codes
53- const remoteErrorMap = await this . fetchRemoteCodes ( )
54- this . errorMap = remoteErrorMap
51+ await retry (
52+ async ( ) => {
53+ // Clear existing error code mapping
54+ this . errorMap = { }
55+ // Get remote error codes
56+ const remoteErrorMap = await this . fetchRemoteCodes ( )
57+ this . errorMap = remoteErrorMap
58+ this . provider . setValue ( "errorCode" , remoteErrorMap )
59+ } ,
60+ {
61+ retries : 2 ,
62+ } ,
63+ )
5564 } catch ( error ) {
65+ const { errorCode } = await this . provider . getState ( )
66+ this . errorMap = ( errorCode ?? { } ) as IErrorMap
5667 console . error ( "Failed to refresh error codes:" , error )
5768 }
5869 }
@@ -65,7 +76,7 @@ export class ErrorCodeManager {
6576 try {
6677 const { language, apiConfiguration } = await this . provider . getState ( )
6778 const baseUrl = apiConfiguration . zgsmBaseUrl || ZgsmAuthConfig . getInstance ( ) . getDefaultApiBaseUrl ( )
68- const response = await axios . get ( `${ baseUrl } /shenma/api/v1 /error-code/error_codes_${ language } .json` )
79+ const response = await axios . get ( `${ baseUrl } /costrict /error-code/error_codes_${ language } .json` )
6980 return response . data
7081 } catch ( error ) {
7182 console . error ( "Failed to fetch remote error codes:" , error )
@@ -124,7 +135,7 @@ export class ErrorCodeManager {
124135 let status = error . status as number
125136 const { code, headers } = error
126137 const requestId = headers ?. get ( "x-request-id" ) ?? null
127- const { apiConfiguration } = await this . provider . getState ( )
138+ const { apiConfiguration, errorCode } = await this . provider . getState ( )
128139 const { zgsmApiKeyExpiredAt, zgsmApiKeyUpdatedAt, isOldModeLoginState } = this . parseZgsmTokenInfo (
129140 apiConfiguration . zgsmAccessToken ,
130141 )
@@ -159,7 +170,8 @@ export class ErrorCodeManager {
159170 "quota-manager.voucher_expired" ,
160171 ]
161172 if ( code ) {
162- let { message, solution } = this . errorMap [ code ] || this . unknownError
173+ const errorMap = Object . keys ( this . errorMap ) . length > 0 ? this . errorMap : ( errorCode ?? { } ) // Use fetched error codes or fallback to provider state
174+ let { message, solution } = errorMap [ code ] || this . unknownError
163175 if ( authRequiredCodes . includes ( code ) ) {
164176 rawError = message
165177 message = defaultError [ "401" ] . message
0 commit comments