mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Improve project failed state
This commit is contained in:
+30
-9
@@ -3,15 +3,36 @@ import type { Config } from '@app/config';
|
||||
export async function get(path: string, config: Config): Promise<any | null> {
|
||||
if (! config.seed.api) return null;
|
||||
|
||||
const response = await fetch(`${config.seed.api}/v1/${path}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
const url = `${config.seed.api}/v1/${path}`;
|
||||
|
||||
if (! response.ok) {
|
||||
return null;
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
|
||||
if (! response.ok) {
|
||||
return null;
|
||||
}
|
||||
return response.json();
|
||||
} catch {
|
||||
throw new ApiError(url, "API request failed");
|
||||
}
|
||||
}
|
||||
|
||||
class ApiError extends Error {
|
||||
url: string;
|
||||
|
||||
constructor(url: string, message: string) {
|
||||
super(message);
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, ApiError);
|
||||
}
|
||||
|
||||
this.name = "ApiError";
|
||||
this.url = url;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user