@aptly-as/types
Advanced tools
Comparing version 2.7.15 to 2.8.0
@@ -86,7 +86,2 @@ export * from './document.js'; | ||
} | ||
export declare enum AptlyErrorCode { | ||
Default = "default", | ||
InvalidFields = "invalid-fields", | ||
SessionExpired = "session-expired" | ||
} | ||
export declare enum AptlyQueueDownloadType { | ||
@@ -93,0 +88,0 @@ Document = "document", |
@@ -98,8 +98,2 @@ export * from './document.js'; | ||
})(AptlySignageSignerRef || (AptlySignageSignerRef = {})); | ||
export var AptlyErrorCode; | ||
(function (AptlyErrorCode) { | ||
AptlyErrorCode["Default"] = "default"; | ||
AptlyErrorCode["InvalidFields"] = "invalid-fields"; | ||
AptlyErrorCode["SessionExpired"] = "session-expired"; | ||
})(AptlyErrorCode || (AptlyErrorCode = {})); | ||
export var AptlyQueueDownloadType; | ||
@@ -106,0 +100,0 @@ (function (AptlyQueueDownloadType) { |
@@ -0,13 +1,15 @@ | ||
import { AptlyErrorCode } from './error.utils.js'; | ||
export interface AptlyErrorBody { | ||
name: 'AptlyError'; | ||
status: number; | ||
title: string; | ||
message: string; | ||
id?: string; | ||
code?: number; | ||
code?: AptlyErrorCode; | ||
detail?: string; | ||
errors?: AptlyErrorBodySimple[]; | ||
link?: string; | ||
title?: string; | ||
error?: string; | ||
} | ||
export type AptlyErrorBodySimple = Pick<AptlyErrorBody, 'status' | 'title' | 'detail' | 'link'>; | ||
export type AptlyErrorBodySimple = Pick<AptlyErrorBody, 'status' | 'message' | 'detail' | 'link'>; | ||
export declare class AptlyError extends Error { | ||
@@ -17,8 +19,10 @@ readonly data: Omit<AptlyErrorBody, 'name'>; | ||
readonly name = "AptlyError"; | ||
id: string; | ||
readonly _status: number; | ||
readonly id: string; | ||
static fromFetchResponse(response: Response): Promise<AptlyError>; | ||
static fromResponse(response: Response): Promise<AptlyError>; | ||
constructor(data: Omit<AptlyErrorBody, 'name'>, error?: Error | undefined); | ||
static fromFetchResponse(response: Response): Promise<AptlyError>; | ||
get status(): number; | ||
get title(): string; | ||
get code(): number | undefined; | ||
get code(): AptlyErrorCode | undefined; | ||
get detail(): string | undefined; | ||
@@ -25,0 +29,0 @@ get link(): string | undefined; |
export class AptlyError extends Error { | ||
constructor(data, error) { | ||
super(data.title); | ||
this.data = data; | ||
this.error = error; | ||
this.name = 'AptlyError'; | ||
this.id = data.id || ''; | ||
static fromFetchResponse(response) { | ||
return AptlyError.fromResponse(response); | ||
} | ||
static async fromFetchResponse(response) { | ||
static async fromResponse(response) { | ||
if (response.headers.get('content-type') !== 'application/json') { | ||
@@ -19,11 +15,20 @@ const body = await response.json(); | ||
status: response.status, | ||
title: response.statusText, | ||
message: response.statusText, | ||
detail: `Failed to fetch from url: ${response.url}`, | ||
}); | ||
} | ||
constructor(data, error) { | ||
super(data.title || data.message); | ||
this.data = data; | ||
this.error = error; | ||
this.name = 'AptlyError'; | ||
this._status = 500; | ||
this._status = data.status; | ||
this.id = data.id || ''; | ||
} | ||
get status() { | ||
return this.data.status; | ||
return this._status; | ||
} | ||
get title() { | ||
return this.data.title; | ||
return this.data.message; | ||
} | ||
@@ -30,0 +35,0 @@ get code() { |
export * from './error.js'; | ||
export * from './error.utils.js'; |
export * from './error.js'; | ||
export * from './error.utils.js'; |
{ | ||
"name": "@aptly-as/types", | ||
"version": "2.7.15", | ||
"version": "2.8.0", | ||
"description": "Aptly types and enums", | ||
@@ -5,0 +5,0 @@ "type": "module", |
114191
114
3127