-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
Every public API method in MpakClient (8 in total) repeats the same two-block error check after every fetchWithTimeout call:
if (response.status === 404) {
throw new MpakNotFoundError(...);
}
if (!response.ok) {
throw new MpakNetworkError(`Failed to ...: HTTP ${response.status}`);
}This means adding a new error type (e.g. 429 rate limit, 401 unauthorized) requires touching every single method individually.
Proposed fix
Replace fetchWithTimeout with a private apiGet method that owns the full lifecycle of a registry API call — timeout, headers, error handling, and JSON parsing — and returns Promise<unknown>:
private async apiGet(
url: string,
init?: RequestInit & { notFoundKey?: string },
): Promise<unknown>- If
notFoundKeyis provided and the response is 404, throwMpakNotFoundError(notFoundKey) - If response is not ok, throw
MpakNetworkError - If response is ok, return
response.json()
Callers then become a single line each:
return this.apiGet(url, { notFoundKey: name }) as Promise<BundleDetailResponse>;Future error types are added in one place only.
Out of scope
Content downloads (downloadSkillContent, skill resolution) fetch arbitrary external URLs and return raw text — they are a different concern and not covered by this change.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels