fix(api): improve error handling for API requests
This commit is contained in:
@@ -62,6 +62,10 @@ function FormerResolveSpecAPI(options: {
|
||||
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
if (text && text.length > 4) {
|
||||
throw new Error(`${text}`);
|
||||
}
|
||||
throw new Error(`API request failed with status ${response.status}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ function FormerRestHeadSpecAPI(options: {
|
||||
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
if (text && text.length > 4) {
|
||||
throw new Error(`${text}`);
|
||||
}
|
||||
throw new Error(`API request failed with status ${response.status}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user