tweak: better err msgs
Some checks are pending
deploy / deploy (push) Waiting to run
format / format (push) Waiting to run
snapshot / publish (push) Waiting to run
test / test (push) Waiting to run
Update Nix Hashes / update (push) Waiting to run

This commit is contained in:
Aiden Cline 2025-12-01 01:33:32 -06:00
parent f6262460ff
commit b1b82977ec
2 changed files with 23 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import type { ModelMessage } from "ai"
import type { APICallError, ModelMessage } from "ai"
import { STATUS_CODES } from "http"
import { unique } from "remeda"
import type { JSONSchema } from "zod/v4/core"
@ -308,11 +309,28 @@ export namespace ProviderTransform {
return schema
}
export function error(providerID: string, message: string) {
export function error(providerID: string, error: APICallError) {
let message = error.message
if (providerID === "github-copilot" && message.includes("The requested model is not supported")) {
message +=
return (
message +
"\n\nMake sure the model is enabled in your copilot settings: https://github.com/settings/copilot/features"
)
}
return message
if (!error.responseBody || (error.statusCode && message !== STATUS_CODES[error.statusCode])) {
return message
}
try {
const body = JSON.parse(error.responseBody)
// try to extract common error message fields
const errMsg = body.message || body.error
if (errMsg && typeof errMsg === "string") {
return `${message}: ${errMsg}`
}
} catch {}
return `${message}: ${error.responseBody}`
}
}

View file

@ -739,7 +739,7 @@ export namespace MessageV2 {
{ cause: e },
).toObject()
case APICallError.isInstance(e):
const message = ProviderTransform.error(ctx.providerID, e.message)
const message = ProviderTransform.error(ctx.providerID, e)
return new MessageV2.APIError(
{
message,