mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
refactor: Add error handling for network calls and apply consistent formatting across networking functions.
This commit is contained in:
parent
ee634375e2
commit
af41713aa1
1 changed files with 28 additions and 31 deletions
|
|
@ -83,7 +83,7 @@ const defaultServerRootPath = "/";
|
|||
export let serverRootPath = defaultServerRootPath;
|
||||
export let proxyBaseUrl = defaultProxyBaseUrl;
|
||||
if (isLocal != true) {
|
||||
console.log = function () { };
|
||||
console.log = function () {};
|
||||
}
|
||||
|
||||
const getWindowLocation = () => {
|
||||
|
|
@ -2110,6 +2110,10 @@ export const modelHubPublicModelsCall = async () => {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error(`modelHubPublicModelsCall failed with status ${response.status}`);
|
||||
return [];
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
|
|
@ -2121,6 +2125,10 @@ export const agentHubPublicModelsCall = async () => {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error(`agentHubPublicModelsCall failed with status ${response.status}`);
|
||||
return [];
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
|
|
@ -2132,6 +2140,10 @@ export const mcpHubPublicServersCall = async () => {
|
|||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error(`mcpHubPublicServersCall failed with status ${response.status}`);
|
||||
return [];
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
|
|
@ -2466,7 +2478,7 @@ export const modelAvailableCall = async (
|
|||
teamID: string | null = null,
|
||||
include_model_access_groups: boolean = false,
|
||||
only_model_access_groups: boolean = false,
|
||||
scope?: string
|
||||
scope?: string,
|
||||
) => {
|
||||
/**
|
||||
* Get all the models user has access to
|
||||
|
|
@ -5575,7 +5587,9 @@ export const createPolicyAttachmentCall = async (accessToken: string, attachment
|
|||
|
||||
export const deletePolicyAttachmentCall = async (accessToken: string, attachmentId: string) => {
|
||||
try {
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/policies/attachments/${attachmentId}` : `/policies/attachments/${attachmentId}`;
|
||||
const url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/policies/attachments/${attachmentId}`
|
||||
: `/policies/attachments/${attachmentId}`;
|
||||
const response = await fetch(url, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
|
@ -5601,7 +5615,9 @@ export const deletePolicyAttachmentCall = async (accessToken: string, attachment
|
|||
|
||||
export const getResolvedGuardrails = async (accessToken: string, policyId: string) => {
|
||||
try {
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/policies/${policyId}/resolved-guardrails` : `/policies/${policyId}/resolved-guardrails`;
|
||||
const url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/policies/${policyId}/resolved-guardrails`
|
||||
: `/policies/${policyId}/resolved-guardrails`;
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
|
|
@ -8576,9 +8592,7 @@ export const updateUiSettings = async (accessToken: string, settings: Record<str
|
|||
export const getClaudeCodeMarketplace = async () => {
|
||||
try {
|
||||
const proxyBaseUrl = getProxyBaseUrl();
|
||||
const url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/claude-code/marketplace.json`
|
||||
: `/claude-code/marketplace.json`;
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/claude-code/marketplace.json` : `/claude-code/marketplace.json`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
|
|
@ -8607,10 +8621,7 @@ export const getClaudeCodeMarketplace = async () => {
|
|||
* @param accessToken - Admin access token
|
||||
* @param enabledOnly - If true, only return enabled plugins (default: false)
|
||||
*/
|
||||
export const getClaudeCodePluginsList = async (
|
||||
accessToken: string,
|
||||
enabledOnly: boolean = false
|
||||
) => {
|
||||
export const getClaudeCodePluginsList = async (accessToken: string, enabledOnly: boolean = false) => {
|
||||
try {
|
||||
const proxyBaseUrl = getProxyBaseUrl();
|
||||
const url = proxyBaseUrl
|
||||
|
|
@ -8645,10 +8656,7 @@ export const getClaudeCodePluginsList = async (
|
|||
* @param accessToken - Admin access token
|
||||
* @param pluginName - Name of the plugin
|
||||
*/
|
||||
export const getClaudeCodePluginDetails = async (
|
||||
accessToken: string,
|
||||
pluginName: string
|
||||
) => {
|
||||
export const getClaudeCodePluginDetails = async (accessToken: string, pluginName: string) => {
|
||||
try {
|
||||
const proxyBaseUrl = getProxyBaseUrl();
|
||||
const url = proxyBaseUrl
|
||||
|
|
@ -8694,13 +8702,11 @@ export const registerClaudeCodePlugin = async (
|
|||
homepage?: string;
|
||||
keywords?: string[];
|
||||
category?: string;
|
||||
}
|
||||
},
|
||||
) => {
|
||||
try {
|
||||
const proxyBaseUrl = getProxyBaseUrl();
|
||||
const url = proxyBaseUrl
|
||||
? `${proxyBaseUrl}/claude-code/plugins`
|
||||
: `/claude-code/plugins`;
|
||||
const url = proxyBaseUrl ? `${proxyBaseUrl}/claude-code/plugins` : `/claude-code/plugins`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
|
|
@ -8731,10 +8737,7 @@ export const registerClaudeCodePlugin = async (
|
|||
* @param accessToken - Admin access token
|
||||
* @param pluginName - Name of the plugin to enable
|
||||
*/
|
||||
export const enableClaudeCodePlugin = async (
|
||||
accessToken: string,
|
||||
pluginName: string
|
||||
) => {
|
||||
export const enableClaudeCodePlugin = async (accessToken: string, pluginName: string) => {
|
||||
try {
|
||||
const proxyBaseUrl = getProxyBaseUrl();
|
||||
const url = proxyBaseUrl
|
||||
|
|
@ -8769,10 +8772,7 @@ export const enableClaudeCodePlugin = async (
|
|||
* @param accessToken - Admin access token
|
||||
* @param pluginName - Name of the plugin to disable
|
||||
*/
|
||||
export const disableClaudeCodePlugin = async (
|
||||
accessToken: string,
|
||||
pluginName: string
|
||||
) => {
|
||||
export const disableClaudeCodePlugin = async (accessToken: string, pluginName: string) => {
|
||||
try {
|
||||
const proxyBaseUrl = getProxyBaseUrl();
|
||||
const url = proxyBaseUrl
|
||||
|
|
@ -8807,10 +8807,7 @@ export const disableClaudeCodePlugin = async (
|
|||
* @param accessToken - Admin access token
|
||||
* @param pluginName - Name of the plugin to delete
|
||||
*/
|
||||
export const deleteClaudeCodePlugin = async (
|
||||
accessToken: string,
|
||||
pluginName: string
|
||||
) => {
|
||||
export const deleteClaudeCodePlugin = async (accessToken: string, pluginName: string) => {
|
||||
try {
|
||||
const proxyBaseUrl = getProxyBaseUrl();
|
||||
const url = proxyBaseUrl
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue