@evergis/api
Advanced tools
Comparing version 0.1.59 to 0.1.60
@@ -12,5 +12,2 @@ import { HttpClient } from './__generated__/HttpClient'; | ||
}; | ||
export declare enum ApiEvent { | ||
ConnectionLost = "ConnectionLost" | ||
} | ||
export declare class Api extends EventEmitter { | ||
@@ -17,0 +14,0 @@ protected readonly http: HttpClient; |
@@ -8,6 +8,3 @@ import { defaultApiConfig } from './defaultApiConfig'; | ||
import { Print } from './services/Print'; | ||
export var ApiEvent; | ||
(function (ApiEvent) { | ||
ApiEvent["ConnectionLost"] = "ConnectionLost"; | ||
})(ApiEvent || (ApiEvent = {})); | ||
import { ApiEvent } from './ApiEvent'; | ||
export class Api extends EventEmitter { | ||
@@ -14,0 +11,0 @@ constructor({ url, wsUrl, config = defaultApiConfig }) { |
import { HttpClient, HTTPError } from '../__generated__/HttpClient'; | ||
import { ApiEvent } from '../Api'; | ||
import { ApiEvent } from '../ApiEvent'; | ||
import { errorHandler } from './errorHandler'; | ||
const apiEventsByResponseStatus = { | ||
401: ApiEvent.Unauthorized, | ||
403: ApiEvent.ConnectionLost, | ||
}; | ||
export class ExtendedHttpClient extends HttpClient { | ||
@@ -13,5 +17,5 @@ constructor(prefixUrl, emitter) { | ||
response => { | ||
if (response.status === 403) { | ||
emitter && | ||
emitter.emit(ApiEvent.ConnectionLost, errorHandler(new HTTPError(response))); | ||
const apiEvent = apiEventsByResponseStatus[response.status]; | ||
if (emitter && apiEvent) { | ||
emitter.emit(apiEvent, errorHandler(new HTTPError(response))); | ||
} | ||
@@ -18,0 +22,0 @@ return response; |
{ | ||
"name": "@evergis/api", | ||
"version": "0.1.59", | ||
"version": "0.1.60", | ||
"license": "ISC", | ||
@@ -5,0 +5,0 @@ "author": "everpoint", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
318838
200
6700