Skip to content

Commit

Permalink
expose error classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed Dec 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7fb0e97 commit a8bfdb5
Showing 11 changed files with 36 additions and 17 deletions.
15 changes: 11 additions & 4 deletions dist/main.d.ts
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ interface ClientData {
/**
* Interface representing the structure of an API error.
*/
interface ApiError$1 {
interface IApiError {
/**
* The error message.
*/
@@ -109,7 +109,7 @@ interface ApiError$1 {
/**
* Represents an API error with a specific code and optional details.
*/
declare class ApiError extends Error implements ApiError$1 {
declare class ApiError extends Error implements IApiError {
/**
* The error code representing the type of API error.
*/
@@ -1164,7 +1164,7 @@ interface AuthData {
version?: string;
}

interface AuthError {
interface IAuthError {
code: number;
error: string;
error_description: string;
@@ -3325,4 +3325,11 @@ declare class LokaliseAuth {
private handleReject;
}

export { type ApiError$1 as ApiError, type AuthData, type AuthError, type BillingDetailsParams, type Branch$1 as Branch, type BranchDeleted, type BranchMerged, type BranchParams, type BulkResult, type BulkUpdateKeyParams, type CardDeleted, type ClientData, type Comment$1 as Comment, type CommentData, type CommentDeleted, type Contributor$1 as Contributor, type ContributorCreateData, type ContributorDeleted, type ContributorLanguages, type ContributorRights, type ContributorUpdateData, type CreateCardParams, type CreateKeyData, type CreateKeyParams, type CreateLanguageParams, type CreateOrderParams, type CreateProjectParams, type CreateScreenshotParams, type CreateSnapshotParams, type CreateTaskParams, type CreateTranslationStatusParams, type CreateWebhookParams, type CursorPaginatedResult$1 as CursorPaginatedResult, type CursorPagination, type DownloadBundle, type DownloadFileParams, type File$1 as File, type FileDeleted, type Filenames, type GetKeyParams, type GetSegmentParams, type GetTranslationParams, type HttpMethod, type Jwt$2 as Jwt, type Key$1 as Key, type KeyDeleted, type KeyParamsWithPagination, type KeyProjectPagination, type KeysBulkDeleted, type Language$1 as Language, type LanguageDeleted, type ListFileParams, type ListSegmentParams, type ListTaskParams, type ListTranslationParams, LokaliseApi, LokaliseApiOAuth, LokaliseApiOta, LokaliseAuth, LokaliseOtaBundles, type MergeBranchParams, type NumericBool, type Order$1 as Order, type OtaBundle$1 as OtaBundle, type OtaBundleArchive$1 as OtaBundleArchive, type OtaBundleUpdateData, type OtaFramework, type OtaFreezePeriod$1 as OtaFreezePeriod, type OtaFreezePeriodParams, type OtaProjectFramework, type OtaRequestBundleParams, type OtaResourceDeleted, type OtaSdkToken$1 as OtaSdkToken, type OtaStatistics$1 as OtaStatistics, type OtaTeamProject, type OtaTeamProjectFramework, type OtaUsageParams, type PaginatedResult$1 as PaginatedResult, type PaginationParams, type PaymentCard$1 as PaymentCard, type Project$1 as Project, type ProjectAndKey, type ProjectDeleted, type ProjectEmptied, type ProjectListParams, type ProjectOnly, type ProjectSettings, type ProjectStatistics, type ProjectWithPagination, type QueuedProcess$1 as QueuedProcess, type RefreshTokenResponse$1 as RefreshTokenResponse, type RequestTokenResponse$1 as RequestTokenResponse, type Screenshot$1 as Screenshot, type ScreenshotData, type ScreenshotDeleted, type Segment$1 as Segment, type Snapshot$1 as Snapshot, type SnapshotDeleted, type SupportedPlatforms, type Task$1 as Task, type TaskDeleted, type TaskLanguage, type Team$1 as Team, type TeamOnly, type TeamUser$1 as TeamUser, type TeamUserBillingDetails$2 as TeamUserBillingDetails, type TeamUserDeleted, type TeamUserParams, type TeamWithPagination, type Translation$1 as Translation, type TranslationData, type TranslationProvider$1 as TranslationProvider, type TranslationStatus$1 as TranslationStatus, type TranslationStatusColors, type TranslationStatusDeleted, type UpdateKeyData, type UpdateKeyDataWithId, type UpdateLanguageParams, type UpdateProjectParams, type UpdateScreenshotParams, type UpdateSegmentBodyParams, type UpdateSegmentReqParams, type UpdateTaskParams, type UpdateTranslationParams, type UpdateTranslationStatusParams, type UpdateWebhookParams, type UserGroup$1 as UserGroup, type UserGroupDeleted, type UserGroupParams, type Webhook$1 as Webhook, type WebhookDeleted, type WebhookEventLangMap, type WebhookProjectBranchAdded, type WebhookProjectBranchDeleted, type WebhookProjectBranchMerged, type WebhookProjectContributorAdded, type WebhookProjectContributorAddedPublic, type WebhookProjectContributorDeleted, type WebhookProjectCopied, type WebhookProjectDeleted, type WebhookProjectExported, type WebhookProjectImported, type WebhookProjectKeyAdded, type WebhookProjectKeyCommentAdded, type WebhookProjectKeyModified, type WebhookProjectKeysAdded, type WebhookProjectKeysDeleted, type WebhookProjectKeysModified, type WebhookProjectLanguageRemoved, type WebhookProjectLanguageSettingsChanged, type WebhookProjectLanguagesAdded, type WebhookProjectSnapshotCreated, type WebhookProjectTaskClosed, type WebhookProjectTaskCreated, type WebhookProjectTaskDeleted, type WebhookProjectTaskInitialTmLeverageCalculated, type WebhookProjectTaskLanguageClosed, type WebhookProjectTaskQueued, type WebhookProjectTranslationProofread, type WebhookProjectTranslationUpdated, type WebhookProjectTranslationsProofread, type WebhookProjectTranslationsUpdated, type WebhookRegenerated, type WebhookTeamOrderCompleted, type WebhookTeamOrderCreated, type WebhookTeamOrderDeleted };
declare class AuthError extends BaseModel implements IAuthError {
code: number;
error: string;
error_description: string;
error_uri?: string;
}

export { ApiError, type AuthData, AuthError, type BillingDetailsParams, type Branch$1 as Branch, type BranchDeleted, type BranchMerged, type BranchParams, type BulkResult, type BulkUpdateKeyParams, type CardDeleted, type ClientData, type Comment$1 as Comment, type CommentData, type CommentDeleted, type Contributor$1 as Contributor, type ContributorCreateData, type ContributorDeleted, type ContributorLanguages, type ContributorRights, type ContributorUpdateData, type CreateCardParams, type CreateKeyData, type CreateKeyParams, type CreateLanguageParams, type CreateOrderParams, type CreateProjectParams, type CreateScreenshotParams, type CreateSnapshotParams, type CreateTaskParams, type CreateTranslationStatusParams, type CreateWebhookParams, type CursorPaginatedResult$1 as CursorPaginatedResult, type CursorPagination, type DownloadBundle, type DownloadFileParams, type File$1 as File, type FileDeleted, type Filenames, type GetKeyParams, type GetSegmentParams, type GetTranslationParams, type HttpMethod, type IApiError, type IAuthError, type Jwt$2 as Jwt, type Key$1 as Key, type KeyDeleted, type KeyParamsWithPagination, type KeyProjectPagination, type KeysBulkDeleted, type Language$1 as Language, type LanguageDeleted, type ListFileParams, type ListSegmentParams, type ListTaskParams, type ListTranslationParams, LokaliseApi, LokaliseApiOAuth, LokaliseApiOta, LokaliseAuth, LokaliseOtaBundles, type MergeBranchParams, type NumericBool, type Order$1 as Order, type OtaBundle$1 as OtaBundle, type OtaBundleArchive$1 as OtaBundleArchive, type OtaBundleUpdateData, type OtaFramework, type OtaFreezePeriod$1 as OtaFreezePeriod, type OtaFreezePeriodParams, type OtaProjectFramework, type OtaRequestBundleParams, type OtaResourceDeleted, type OtaSdkToken$1 as OtaSdkToken, type OtaStatistics$1 as OtaStatistics, type OtaTeamProject, type OtaTeamProjectFramework, type OtaUsageParams, type PaginatedResult$1 as PaginatedResult, type PaginationParams, type PaymentCard$1 as PaymentCard, type Project$1 as Project, type ProjectAndKey, type ProjectDeleted, type ProjectEmptied, type ProjectListParams, type ProjectOnly, type ProjectSettings, type ProjectStatistics, type ProjectWithPagination, type QueuedProcess$1 as QueuedProcess, type RefreshTokenResponse$1 as RefreshTokenResponse, type RequestTokenResponse$1 as RequestTokenResponse, type Screenshot$1 as Screenshot, type ScreenshotData, type ScreenshotDeleted, type Segment$1 as Segment, type Snapshot$1 as Snapshot, type SnapshotDeleted, type SupportedPlatforms, type Task$1 as Task, type TaskDeleted, type TaskLanguage, type Team$1 as Team, type TeamOnly, type TeamUser$1 as TeamUser, type TeamUserBillingDetails$2 as TeamUserBillingDetails, type TeamUserDeleted, type TeamUserParams, type TeamWithPagination, type Translation$1 as Translation, type TranslationData, type TranslationProvider$1 as TranslationProvider, type TranslationStatus$1 as TranslationStatus, type TranslationStatusColors, type TranslationStatusDeleted, type UpdateKeyData, type UpdateKeyDataWithId, type UpdateLanguageParams, type UpdateProjectParams, type UpdateScreenshotParams, type UpdateSegmentBodyParams, type UpdateSegmentReqParams, type UpdateTaskParams, type UpdateTranslationParams, type UpdateTranslationStatusParams, type UpdateWebhookParams, type UserGroup$1 as UserGroup, type UserGroupDeleted, type UserGroupParams, type Webhook$1 as Webhook, type WebhookDeleted, type WebhookEventLangMap, type WebhookProjectBranchAdded, type WebhookProjectBranchDeleted, type WebhookProjectBranchMerged, type WebhookProjectContributorAdded, type WebhookProjectContributorAddedPublic, type WebhookProjectContributorDeleted, type WebhookProjectCopied, type WebhookProjectDeleted, type WebhookProjectExported, type WebhookProjectImported, type WebhookProjectKeyAdded, type WebhookProjectKeyCommentAdded, type WebhookProjectKeyModified, type WebhookProjectKeysAdded, type WebhookProjectKeysDeleted, type WebhookProjectKeysModified, type WebhookProjectLanguageRemoved, type WebhookProjectLanguageSettingsChanged, type WebhookProjectLanguagesAdded, type WebhookProjectSnapshotCreated, type WebhookProjectTaskClosed, type WebhookProjectTaskCreated, type WebhookProjectTaskDeleted, type WebhookProjectTaskInitialTmLeverageCalculated, type WebhookProjectTaskLanguageClosed, type WebhookProjectTaskQueued, type WebhookProjectTranslationProofread, type WebhookProjectTranslationUpdated, type WebhookProjectTranslationsProofread, type WebhookProjectTranslationsUpdated, type WebhookRegenerated, type WebhookTeamOrderCompleted, type WebhookTeamOrderCreated, type WebhookTeamOrderDeleted };
6 changes: 6 additions & 0 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions docs/additional_info/exception_handling.md
Original file line number Diff line number Diff line change
@@ -13,13 +13,17 @@ lokaliseApi.projects().list().catch(
Or with async/await:

```js
import { ApiError } from "@lokalise/node-api";

try {
await lokaliseApi.projects().list();
} catch (e) {
console.error(e);
console.log(e.message); // "Request timed out after 1000ms"
console.log(e.code); // 408
console.log(e.details); // { reason: "timeout" }
if (error instanceof ApiError) {
console.log(e.message); // "Request timed out after 1000ms"
console.log(e.code); // 408
console.log(e.details); // { reason: "timeout" }
}
}
```

2 changes: 1 addition & 1 deletion src/interfaces/api_error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Interface representing the structure of an API error.
*/
export interface ApiError {
export interface IApiError {
/**
* The error message.
*/
2 changes: 1 addition & 1 deletion src/interfaces/auth_error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface AuthError {
export interface IAuthError {
code: number;
error: string;
error_description: string;
4 changes: 2 additions & 2 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { AuthData } from "./auth_data.js";
export { ApiError } from "./api_error.js";
export { AuthError } from "./auth_error.js";
export { IApiError } from "./api_error.js";
export { IAuthError } from "./auth_error.js";
export { Branch } from "./branch.js";
export { BulkResult } from "./bulk_result.js";
export { ClientData } from "./client_data.js";
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -10,5 +10,7 @@ export {
LokaliseApiOta,
LokaliseOtaBundles,
};
export { AuthError } from "./models/auth_error.js";
export { ApiError } from "./models/api_error.js";
export * from "./interfaces/index.js";
export type * from "./types/index.js";
4 changes: 2 additions & 2 deletions src/models/api_error.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ApiError as ApiErrorInterface } from "../interfaces/api_error.js";
import type { IApiError } from "../interfaces/api_error.js";

/**
* Represents an API error with a specific code and optional details.
*/
export class ApiError extends Error implements ApiErrorInterface {
export class ApiError extends Error implements IApiError {
/**
* The error code representing the type of API error.
*/
4 changes: 2 additions & 2 deletions src/models/auth_error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AuthError as ErrorInterface } from "../interfaces/auth_error.js";
import type { IAuthError } from "../interfaces/auth_error.js";
import { BaseModel } from "./base_model.js";

export class AuthError extends BaseModel implements ErrorInterface {
export class AuthError extends BaseModel implements IAuthError {
declare code: number;
declare error: string;
declare error_description: string;
2 changes: 1 addition & 1 deletion test/errors/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ProjectWithPagination } from "../../src/main.js";
import { ApiError } from "../../src/models/api_error.js";
import { ApiError } from "../../src/main.js";
import { LokaliseApi, Stub, describe, expect, it, vi } from "../setup.js";

describe("Errors", () => {

0 comments on commit a8bfdb5

Please sign in to comment.