Skip to content

Commit

Permalink
Update ApiError to HubApiError (#156)
Browse files Browse the repository at this point in the history
Co-authored-by: syed mohib <syedMohib44>
  • Loading branch information
syedMohib44 authored Apr 19, 2023
1 parent f8d52d5 commit c19bf42
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/hub/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export async function createApiError(
response: Response,
opts?: { requestId?: string; message?: string }
): Promise<never> {
const error = new ApiError(response.url, response.status, response.headers.get("X-Request-Id") ?? opts?.requestId);
const error = new HubApiError(response.url, response.status, response.headers.get("X-Request-Id") ?? opts?.requestId);

error.message = `Api error with status ${error.statusCode}.${opts?.message ? ` ${opts.message}.` : ""} Request ID: ${
error.requestId
Expand All @@ -24,7 +24,7 @@ export async function createApiError(
/**
* Error thrown when an API call to the Hugging Face Hub fails.
*/
export class ApiError extends Error {
export class HubApiError extends Error {
statusCode: number;
url: string;
requestId?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export type {
SpaceStage,
Task,
} from "./types/public";
export { ApiError, InvalidApiResponseFormatError } from "./error";
export { HubApiError, InvalidApiResponseFormatError } from "./error";
4 changes: 2 additions & 2 deletions packages/hub/src/lib/commit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isFrontend } from "../../../shared/src/isFrontend";
import { HUB_URL } from "../consts";
import { ApiError, createApiError, InvalidApiResponseFormatError } from "../error";
import { HubApiError, createApiError, InvalidApiResponseFormatError } from "../error";
import type {
ApiCommitHeader,
ApiCommitLfsFile,
Expand Down Expand Up @@ -258,7 +258,7 @@ async function* commitIter(params: CommitParams): AsyncGenerator<unknown, Commit
const errorMessage = `Error while doing LFS batch call for ${operations[shas.indexOf(obj.oid)].path}: ${
obj.error.message
}${batchRequestId ? ` - Request ID: ${batchRequestId}` : ""}`;
throw new ApiError(res.url, obj.error.code, batchRequestId, errorMessage);
throw new HubApiError(res.url, obj.error.code, batchRequestId, errorMessage);
}
if (!obj.actions?.upload) {
return;
Expand Down

0 comments on commit c19bf42

Please sign in to comment.