import { Subject, Subscriber, BehaviorSubject } from 'rxjs'; import { InjectionToken } from '@angular/core'; import { HttpRequest, HttpErrorResponse, HttpEvent, HttpResponse } from '@angular/common/http'; import { RequestSender } from './request-sender'; /** * Type of API Error */ export declare enum ApiErrorEventType { ConnectionError = 101, WrongArgumentSyntax = 400, Unauthorized = 401, Forbidden = 403, NotFound = 404, ServerError = 500, UnknownError = 1001 } /** * Type of validation error */ export declare enum ValidationType { RequestValidation = "request", ResponseValidation = "response", ParamsValidation = "params" } /** * Данные глобального события API. */ export interface ApiErrorEventData { originalEvent: HttpErrorResponse; /** * Number of attempts. By default set as 10 and counts down every * new failed attempt. */ remainAttemptsNumber: number; request: HttpRequest; /** * Отправитель запроса. */ sender: RequestSender; /** * Subscriber of request at business layer of app */ subscriber: Subscriber>; /** * Channel for additional events, such as progress. */ statusChanges: Subject> | boolean; type: ApiErrorEventType; /** * @see VIRTUAL_CONNECTION_STATUS */ virtualConnectionStatus: BehaviorSubject; } /** * Событие, сообщающее об ошибках валидации. */ export declare class ValidationError { message: string; /** * Тип ошибки */ type: ValidationType; /** * Отправитель запроса. * todo нужно связать с ApiService. для этого надо вынести это в интерфейс */ sender: any; /** * Схема, с помощью которой производилась валидация. */ schema: any; /** * Значение, которое не прошло валидацию. */ value: any; /** * Сообщения об ошибках валидации. */ errorMessages: string[] | any[]; constructor(message: string, /** * Тип ошибки */ type: ValidationType, /** * Отправитель запроса. * todo нужно связать с ApiService. для этого надо вынести это в интерфейс */ sender: any, /** * Схема, с помощью которой производилась валидация. */ schema: any, /** * Значение, которое не прошло валидацию. */ value: any, /** * Сообщения об ошибках валидации. */ errorMessages: string[] | any[]); } /** * The primary use of {@link ApiErrorHandler} is a handling * validation errors and http errors after validation of response. * For instance, error response with status 500 have to be validated * before, and throws {@link ValidationError} error when validation fails. */ export interface ApiErrorHandler { /** * Handles HTTP-error after validation of response check. * @param errorData */ onHttpError(errorData: ApiErrorEventData): void; /** * When returns `false`, error skips. * @param errorData */ onValidationError(errorData: ValidationError): boolean | void; } export declare const resetApiSubscribers: Subject; /** * @see VIRTUAL_CONNECTION_STATUS */ export declare const virtualConnectionStatus: BehaviorSubject; /** * Dependency of {@link ApiService}. Notifies service about need of a cancelation of * all active request subscribers. */ export declare const RESET_API_SUBSCRIBERS: InjectionToken>; /** * Injection token for {@link ApiErrorHandler}. * Used in {@link ApiService}. */ export declare const API_ERROR_HANDLER: InjectionToken; /** * Tool than facilitate manual managing of a virtual connection status. * Virtual connection status might be manually changed to `false` (connection off), * and further requests will be wait for `true`. */ export declare const VIRTUAL_CONNECTION_STATUS: InjectionToken; /** * Dependency of {@link ApiService}. Disable validation (JSON-Schema) of * request, params and response, when provided `true`. */ export declare const DISABLE_VALIDATION: InjectionToken; export declare const ERROR_EVENTS_PROVIDER: { provide: InjectionToken>; useValue: Subject; }[];