MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / parseMoonshotError

Function parseMoonshotError

web/src/llm-api/moonshot.ts:796–826  ·  view source on GitHub ↗
(response: Response)

Source from the content-addressed store, hash-verified

794}
795
796async function parseMoonshotError(response: Response): Promise<MoonshotError> {
797 const errorText = await response.text()
798 let errorBody: MoonshotError['errorBody']
799 try {
800 const parsed = JSON.parse(errorText)
801 if (parsed?.error?.message) {
802 errorBody = {
803 error: {
804 message: parsed.error.message,
805 code: parsed.error.code ?? null,
806 type: parsed.error.type ?? null,
807 },
808 }
809 } else {
810 errorBody = {
811 error: {
812 message: errorText || response.statusText,
813 code: response.status,
814 },
815 }
816 }
817 } catch {
818 errorBody = {
819 error: {
820 message: errorText || response.statusText,
821 code: response.status,
822 },
823 }
824 }
825 return new MoonshotError(response.status, response.statusText, errorBody)
826}
827
828function creditsToFakeCost(credits: number): number {
829 return credits / ((1 + PROFIT_MARGIN) * 100)

Callers 2

handleMoonshotNonStreamFunction · 0.85
handleMoonshotStreamFunction · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected