Skip to content

Commit c19bf42

Browse files
authored
Update ApiError to HubApiError (#156)
Co-authored-by: syed mohib <syedMohib44>
1 parent f8d52d5 commit c19bf42

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

packages/hub/src/error.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export async function createApiError(
44
response: Response,
55
opts?: { requestId?: string; message?: string }
66
): Promise<never> {
7-
const error = new ApiError(response.url, response.status, response.headers.get("X-Request-Id") ?? opts?.requestId);
7+
const error = new HubApiError(response.url, response.status, response.headers.get("X-Request-Id") ?? opts?.requestId);
88

99
error.message = `Api error with status ${error.statusCode}.${opts?.message ? ` ${opts.message}.` : ""} Request ID: ${
1010
error.requestId
@@ -24,7 +24,7 @@ export async function createApiError(
2424
/**
2525
* Error thrown when an API call to the Hugging Face Hub fails.
2626
*/
27-
export class ApiError extends Error {
27+
export class HubApiError extends Error {
2828
statusCode: number;
2929
url: string;
3030
requestId?: string;

packages/hub/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ export type {
1717
SpaceStage,
1818
Task,
1919
} from "./types/public";
20-
export { ApiError, InvalidApiResponseFormatError } from "./error";
20+
export { HubApiError, InvalidApiResponseFormatError } from "./error";

packages/hub/src/lib/commit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isFrontend } from "../../../shared/src/isFrontend";
22
import { HUB_URL } from "../consts";
3-
import { ApiError, createApiError, InvalidApiResponseFormatError } from "../error";
3+
import { HubApiError, createApiError, InvalidApiResponseFormatError } from "../error";
44
import type {
55
ApiCommitHeader,
66
ApiCommitLfsFile,
@@ -258,7 +258,7 @@ async function* commitIter(params: CommitParams): AsyncGenerator<unknown, Commit
258258
const errorMessage = `Error while doing LFS batch call for ${operations[shas.indexOf(obj.oid)].path}: ${
259259
obj.error.message
260260
}${batchRequestId ? ` - Request ID: ${batchRequestId}` : ""}`;
261-
throw new ApiError(res.url, obj.error.code, batchRequestId, errorMessage);
261+
throw new HubApiError(res.url, obj.error.code, batchRequestId, errorMessage);
262262
}
263263
if (!obj.actions?.upload) {
264264
return;

0 commit comments

Comments
 (0)