From 512e061157b7666043e7fdb7bcde3ed965c1173f Mon Sep 17 00:00:00 2001 From: Mark Davis Date: Tue, 21 Nov 2017 14:48:29 -0800 Subject: [PATCH] 0.1.4: Exposing WebTransportResopnse for the original interfaces (without request bits) to allow transport-agnostic usage of the interfaces. For example, WebSockets do not have the same type of request options or use headers the same way. --- package.json | 2 +- src/SimpleWebRequest.ts | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 469d656..ee05535 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simplerestclients", - "version": "0.1.3", + "version": "0.1.4", "description": "A library of components for accessing RESTful services with javascript/typescript.", "author": "David de Regt ", "scripts": { diff --git a/src/SimpleWebRequest.ts b/src/SimpleWebRequest.ts index b512b62..ea6d0b6 100644 --- a/src/SimpleWebRequest.ts +++ b/src/SimpleWebRequest.ts @@ -12,26 +12,38 @@ import SyncTasks = require('synctasks'); import { ExponentialTime } from './ExponentialTime'; -export interface WebResponseBase { +export interface WebTransportResponseBase { url: string; method: string; - requestOptions: WebRequestOptions; - requestHeaders: _.Dictionary; statusCode: number; statusText: string|undefined; headers: _.Dictionary; } -export interface WebResponse extends WebResponseBase { +export interface WebTransportResponse extends WebTransportResponseBase { body: T; } -export interface WebErrorResponse extends WebResponseBase { +export interface WebTransportErrorResponse extends WebTransportResponseBase { body: any; canceled: boolean; timedOut: boolean; } +export interface RestRequestInResponse { + requestOptions: WebRequestOptions; + requestHeaders: _.Dictionary; +} + +export interface WebResponseBase extends RestRequestInResponse, WebTransportResponseBase { +} + +export interface WebResponse extends RestRequestInResponse, WebTransportResponse { +} + +export interface WebErrorResponse extends RestRequestInResponse, WebTransportErrorResponse { +} + export enum WebRequestPriority { DontCare = 0, Low = 1, @@ -133,7 +145,7 @@ export let SimpleWebRequestOptions: ISimpleWebRequestOptions = { clearTimeout: (id: number) => window.clearTimeout(id) }; -export function DefaultErrorHandler(webRequest: SimpleWebRequestBase, errResp: WebErrorResponse) { +export function DefaultErrorHandler(webRequest: SimpleWebRequestBase, errResp: WebTransportErrorResponse) { if (errResp.canceled || !errResp.statusCode || errResp.statusCode >= 400 && errResp.statusCode < 600) { // Fail canceled/0/4xx/5xx requests immediately. These are permenent failures, and shouldn't have retry logic applied to them. return ErrorHandlingType.DoNotRetry;