@@ -182,26 +182,10 @@ export class ErrorCodeManager {
182182 message = defaultError [ "401" ] . message
183183 solution = defaultError [ "401" ] . solution
184184 error . status = status = 401
185- } else if ( code === "ai-gateway.insufficient_quota" || code === "ai-gateway.star_required" ) {
186- const hash = await this . hashToken ( apiConfiguration . zgsmAccessToken || "" )
187- const baseurl = apiConfiguration . zgsmBaseUrl || ZgsmAuthConfig . getInstance ( ) . getDefaultLoginBaseUrl ( )
188- const isQuota = code === "ai-gateway.insufficient_quota"
189-
190- const solution1 = isQuota
191- ? t ( "apiErrors:solution.ai-gateway.insufficientCredits" )
192- : t ( "apiErrors:solution.ai-gateway.pleaseStarProject" )
193- const solution2 = isQuota
194- ? t ( "apiErrors:solution.ai-gateway.quotaAcquisition" )
195- : t ( "apiErrors:solution.ai-gateway.howToStar" )
196-
197- const checkRemainingQuotaStr = ! isQuota
198- ? `${ t ( "apiErrors:solution.quota-check.checkRemainingQuota" ) } “ <a href='${ baseurl } /credit/manager/credits?state=${ hash } ' style="font-size: 12px;color:#0078d4;text-decoration: none;">${ t ( "apiErrors:solution.quota-check.creditUsageStats" ) } </a> ” ${ t ( "apiErrors:solution.quota-check.viewDetails" ) } `
199- : ""
200-
201- solution = `
202- <span style="color:#E64545;font-size: 12px;">${ solution1 } </span> <a href='${ baseurl } /credit/manager/md-preview?state=${ hash } ' style="font-size: 12px;color:#0078d4;text-decoration: none;">${ solution2 } </a>
203- ${ checkRemainingQuotaStr }
204- `
185+ } else if ( code === "ai-gateway.insufficient_quota" ) {
186+ solution = await this . handleInsufficientQuotaError ( apiConfiguration )
187+ } else if ( code === "ai-gateway.star_required" ) {
188+ solution = await this . handleStarRequiredError ( apiConfiguration )
205189 }
206190 TelemetryService . instance . captureError ( `ApiError_${ code } ` )
207191 this . provider . log ( `[CoStrict#apiErrors] task ${ taskId } .${ instanceId } Raw Error: ${ rawError } ` )
@@ -218,6 +202,47 @@ ${checkRemainingQuotaStr}
218202 this . provider . log ( `[CoStrict#apiErrors] task ${ taskId } .${ instanceId } Raw Error: ${ rawError } ` )
219203 return `${ t ( "apiErrors:request.error_details" ) } \n\n${ message } \n\n${ requestId ? `RequestID: ${ requestId } \n\n` : "" } ${ t ( "apiErrors:request.solution" ) } \n${ solution } `
220204 }
205+
206+ /**
207+ * Handling insufficient quota errors
208+ * @param apiConfiguration api config
209+ * @returns string
210+ */
211+ private async handleInsufficientQuotaError ( apiConfiguration : any ) : Promise < string > {
212+ const hash = await this . hashToken ( apiConfiguration . zgsmAccessToken || "" )
213+ const baseurl = apiConfiguration . zgsmBaseUrl || ZgsmAuthConfig . getInstance ( ) . getDefaultLoginBaseUrl ( )
214+
215+ const solution1 = t ( "apiErrors:solution.ai-gateway.insufficientCredits" )
216+ const solution2 = t ( "apiErrors:solution.ai-gateway.quotaAcquisition" )
217+
218+ const activitiesStr = `${ t ( "apiErrors:solution.activitiesStr.participate" ) } <a href='${ baseurl } /credit/manager/?state=${ hash } &tab=activity' style="font-size: 12px;color:#0078d4;text-decoration: none;">${ t ( "apiErrors:solution.activitiesStr.operationalActivities" ) } </a> ${ t ( "apiErrors:solution.activitiesStr.or" ) } <a href='${ baseurl } /credit/manager/?state=${ hash } &tab=subscription' style="font-size: 12px;color:#0078d4;text-decoration: none;">${ t ( "apiErrors:solution.activitiesStr.purchaseQuota" ) } </a> ${ t ( "apiErrors:solution.activitiesStr.getCreditLimit" ) } `
219+
220+ return `
221+ <span style="color:#E64545;font-size: 12px;">${ solution1 } </span> <a href='${ baseurl } /credit/manager/md-preview' style="font-size: 12px;color:#0078d4;text-decoration: none;">${ solution2 } </a>
222+ \n${ activitiesStr }
223+ `
224+ }
225+
226+ /**
227+ * Handling errors that require starring
228+ * @param apiConfiguration api config
229+ * @returns string
230+ */
231+ private async handleStarRequiredError ( apiConfiguration : any ) : Promise < string > {
232+ const hash = await this . hashToken ( apiConfiguration . zgsmAccessToken || "" )
233+ const baseurl = apiConfiguration . zgsmBaseUrl || ZgsmAuthConfig . getInstance ( ) . getDefaultLoginBaseUrl ( )
234+
235+ const solution1 = t ( "apiErrors:solution.ai-gateway.pleaseStarProject" )
236+ const solution2 = t ( "apiErrors:solution.ai-gateway.howToStar" )
237+
238+ const checkRemainingQuotaStr = `${ t ( "apiErrors:solution.quota-check.checkRemainingQuota" ) } " <a href='${ baseurl } /credit/manager/?state=${ hash } &tab=usage' style="font-size: 12px;color:#0078d4;text-decoration: none;">${ t ( "apiErrors:solution.quota-check.creditUsageStats" ) } </a> " ${ t ( "apiErrors:solution.quota-check.viewDetails" ) } `
239+
240+ return `
241+ <span style="color:#E64545;font-size: 12px;">${ solution1 } </span> <a href='${ baseurl } /credit/manager/md-preview' style="font-size: 12px;color:#0078d4;text-decoration: none;">${ solution2 } </a>
242+ \n${ checkRemainingQuotaStr }
243+ `
244+ }
245+
221246 private async hashToken ( token : string ) {
222247 const encoder = new TextEncoder ( )
223248 const data = encoder . encode ( token )
0 commit comments