@avst-api/commons
Advanced tools
Comparing version 0.1.10 to 0.2.0
@@ -97,2 +97,3 @@ /// <reference types="runtime" /> | ||
export declare function transformToFormData(body: any): FormData; | ||
export declare function performHttpCall<Ok, Err>(connection: string, urlPath: string, method: string, body?: any, additionalHeaders?: HeadersType, skipBodyParsing?: boolean): Promise<Response<Ok | Err>>; | ||
//# sourceMappingURL=index.d.ts.map |
49
index.js
@@ -183,2 +183,51 @@ export class HttpError extends Error { | ||
} | ||
export async function performHttpCall(connection, urlPath, method, body, additionalHeaders, skipBodyParsing = false) { | ||
const headers = getHeaders(body, { ...additionalHeaders, 'x-hzn-connection-id': connection }); | ||
if (body && !(body instanceof FormData) && !(body instanceof ArrayBuffer)) { | ||
body = JSON.stringify(body); | ||
} | ||
try { | ||
const res = await fetch(urlPath, { method, headers, body }); | ||
if (skipBodyParsing) { | ||
const body = await res.text(); | ||
return getResponse(res.headers, res.status, res.statusText, body); | ||
} | ||
else { | ||
try { | ||
const text = await res.text(); | ||
if (text) { | ||
try { | ||
return getResponse(res.headers, res.status, res.statusText, JSON.parse(text)); | ||
} | ||
catch (e) { | ||
if (res.status < 200 || res.status >= 300) { | ||
return getResponse(res.headers, res.status, res.statusText, {}); | ||
} | ||
else { | ||
throw new UnexpectedError(e, `Failed to parse body, original body: ${text}`); | ||
} | ||
} | ||
} | ||
else { | ||
return getResponse(res.headers, res.status, res.statusText, {}); | ||
} | ||
} | ||
catch (e) { | ||
if (e instanceof UnexpectedError) { | ||
throw e; | ||
} | ||
throw new UnexpectedError(e, `Failed to read body`); | ||
} | ||
} | ||
} | ||
catch (error) { | ||
if (error instanceof Error) { | ||
throw error; | ||
} | ||
else { | ||
// Internal Node errors that are not Errors by default | ||
throw new Error(error); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@avst-api/commons", | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"description": "Commons for Adaptavist Managed APIs", | ||
@@ -18,6 +18,6 @@ "main": "index.js", | ||
"author": "Adaptavist", | ||
"license": "ISC", | ||
"license": "UNLICENSED", | ||
"homepage": "https://bitbucket.org/adaptavistlabs/adaptavist-api-common#readme", | ||
"dependencies": { | ||
"@avst-types/runtime": "^0.12.0" | ||
"@avst-types/runtime": "^0.13.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
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
Explicitly Unlicensed Item
License(Experimental) Something was found which is explicitly marked as unlicensed.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
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
23507
328
1
1
1
0
1
+ Added@avst-types/runtime@0.13.1(transitive)
- Removed@avst-types/runtime@0.12.0(transitive)
Updated@avst-types/runtime@^0.13.0