@api-ts/superagent-wrapper
Advanced tools
Comparing version 0.2.0-beta.12 to 0.2.0-beta.13
@@ -10,8 +10,12 @@ import * as h from '@api-ts/io-ts-http'; | ||
}[keyof Route['response']]; | ||
declare type DecodedResponse<Route extends h.HttpRoute> = SuccessfulResponses<Route> | { | ||
export declare type DecodedResponse<Route extends h.HttpRoute> = SuccessfulResponses<Route> | { | ||
status: 'decodeError'; | ||
error: unknown; | ||
error: string; | ||
body: unknown; | ||
original: Response; | ||
}; | ||
export declare class DecodeError extends Error { | ||
readonly decodedResponse: DecodedResponse<h.HttpRoute>; | ||
constructor(message: string, decodedResponse: DecodedResponse<h.HttpRoute>); | ||
} | ||
declare type ExpectedDecodedResponse<Route extends h.HttpRoute, StatusCode extends keyof Route['response']> = DecodedResponse<Route> & { | ||
@@ -18,0 +22,0 @@ status: StatusCode; |
@@ -26,6 +26,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.requestForRoute = exports.supertestRequestFactory = exports.superagentRequestFactory = void 0; | ||
exports.requestForRoute = exports.supertestRequestFactory = exports.superagentRequestFactory = exports.DecodeError = void 0; | ||
const E = __importStar(require("fp-ts/Either")); | ||
const PathReporter = __importStar(require("io-ts/lib/PathReporter")); | ||
const url_1 = require("url"); | ||
const function_1 = require("fp-ts/function"); | ||
class DecodeError extends Error { | ||
constructor(message, decodedResponse) { | ||
super(message); | ||
this.decodedResponse = decodedResponse; | ||
} | ||
} | ||
exports.DecodeError = DecodeError; | ||
const decodedResponse = (res) => res; | ||
@@ -80,3 +88,3 @@ const METHOD_MAP = { | ||
status: 'decodeError', | ||
error, | ||
error: PathReporter.failure(error).join('\n'), | ||
body: res.body, | ||
@@ -87,7 +95,10 @@ original: res, | ||
patchedReq.decodeExpecting = (status) => patchedReq.decode().then((res) => { | ||
var _a; | ||
if (res.status !== status) { | ||
const error = (_a = res.error) !== null && _a !== void 0 ? _a : `Unexpected status code ${String(res.status)}`; | ||
throw new Error(JSON.stringify(error)); | ||
if (res.original.status !== status) { | ||
const error = `Unexpected response ${String(res.original.status)}: ${JSON.stringify(res.original.body)}`; | ||
throw new DecodeError(error, res); | ||
} | ||
else if (res.status === 'decodeError') { | ||
const error = `Could not decode response ${String(res.original.status)}: ${JSON.stringify(res.original.body)}`; | ||
throw new DecodeError(error, res); | ||
} | ||
else { | ||
@@ -94,0 +105,0 @@ return res; |
{ | ||
"name": "@api-ts/superagent-wrapper", | ||
"version": "0.2.0-beta.12", | ||
"version": "0.2.0-beta.13", | ||
"description": "Make type-safe HTTP requests with superagent", | ||
@@ -5,0 +5,0 @@ "author": "Patrick McLaughlin <patrickmclaughlin@bitgo.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24020
228