mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:20:44 +00:00
refactor: share provider HTTP error parsing
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
createProviderHttpError,
|
||||
formatProviderHttpErrorMessage,
|
||||
} from "openclaw/plugin-sdk/provider-http";
|
||||
import {
|
||||
buildSearchCacheKey,
|
||||
buildUnsupportedSearchFilterResponse,
|
||||
@@ -81,11 +85,8 @@ async function runGeminiSearch(params: {
|
||||
},
|
||||
async (res) => {
|
||||
if (!res.ok) {
|
||||
const safeDetail = ((await res.text()) || res.statusText).replace(
|
||||
/key=[^&\s]+/giu,
|
||||
"key=***",
|
||||
);
|
||||
throw new Error(`Gemini API error (${res.status}): ${safeDetail}`);
|
||||
const error = await createProviderHttpError(res, "Gemini API error");
|
||||
throw new Error(error.message.replace(/key=[^&\s]+/giu, "key=***"));
|
||||
}
|
||||
|
||||
let data: GeminiGroundingResponse;
|
||||
@@ -99,7 +100,11 @@ async function runGeminiSearch(params: {
|
||||
if (data.error) {
|
||||
const rawMessage = data.error.message || data.error.status || "unknown";
|
||||
throw new Error(
|
||||
`Gemini API error (${data.error.code}): ${rawMessage.replace(/key=[^&\s]+/giu, "key=***")}`,
|
||||
formatProviderHttpErrorMessage({
|
||||
label: "Gemini API error",
|
||||
status: data.error.code ?? 0,
|
||||
detail: rawMessage.replace(/key=[^&\s]+/giu, "key=***"),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user