@twurple/api-call
Advanced tools
Comparing version 5.1.0-pre.3 to 5.1.0-pre.4
@@ -7,2 +7,3 @@ "use strict"; | ||
const qs_1 = require("@d-fischer/qs"); | ||
const HttpStatusCodeError_1 = require("./errors/HttpStatusCodeError"); | ||
const transform_1 = require("./helpers/transform"); | ||
@@ -57,5 +58,11 @@ const url_1 = require("./helpers/url"); | ||
async function callTwitchApi(options, clientId, accessToken, fetchOptions = {}) { | ||
var _a; | ||
const response = await callTwitchApiRaw(options, clientId, accessToken, fetchOptions); | ||
if (!response.ok) { | ||
const isJson = response.headers.get('Content-Type') === 'application/json'; | ||
const text = isJson ? JSON.stringify(await response.json(), null, 2) : await response.text(); | ||
throw new HttpStatusCodeError_1.HttpStatusCodeError(response.status, response.statusText, options.url, (_a = options.method) !== null && _a !== void 0 ? _a : 'GET', text, isJson); | ||
} | ||
return await transform_1.transformTwitchApiResponse(response); | ||
} | ||
exports.callTwitchApi = callTwitchApi; |
@@ -7,8 +7,12 @@ import { CustomError } from '@twurple/common'; | ||
private readonly _statusCode; | ||
private readonly _url; | ||
private readonly _method; | ||
private readonly _body; | ||
/** @private */ | ||
constructor(_statusCode: number, statusText: string, _body: string, isJson: boolean); | ||
constructor(_statusCode: number, statusText: string, _url: string, _method: string, _body: string, isJson: boolean); | ||
get statusCode(): number; | ||
get url(): string; | ||
get method(): string; | ||
get body(): string; | ||
} | ||
//# sourceMappingURL=HttpStatusCodeError.d.ts.map |
@@ -10,5 +10,7 @@ "use strict"; | ||
/** @private */ | ||
constructor(_statusCode, statusText, _body, isJson) { | ||
super(`Encountered HTTP status code ${_statusCode}: ${statusText}\n\nBody:\n${!isJson && _body.length > 150 ? `${_body.substr(0, 147)}...` : _body}`); | ||
constructor(_statusCode, statusText, _url, _method, _body, isJson) { | ||
super(`Encountered HTTP status code ${_statusCode}: ${statusText}\n\nURL: ${_url}\nMethod: ${_method}\nBody:\n${!isJson && _body.length > 150 ? `${_body.substr(0, 147)}...` : _body}`); | ||
this._statusCode = _statusCode; | ||
this._url = _url; | ||
this._method = _method; | ||
this._body = _body; | ||
@@ -19,2 +21,8 @@ } | ||
} | ||
get url() { | ||
return this._url; | ||
} | ||
get method() { | ||
return this._method; | ||
} | ||
get body() { | ||
@@ -21,0 +29,0 @@ return this._body; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transformTwitchApiResponse = void 0; | ||
const HttpStatusCodeError_1 = require("../errors/HttpStatusCodeError"); | ||
/** @private */ | ||
async function transformTwitchApiResponse(response) { | ||
if (!response.ok) { | ||
const isJson = response.headers.get('Content-Type') === 'application/json'; | ||
const text = isJson ? JSON.stringify(await response.json(), null, 2) : await response.text(); | ||
throw new HttpStatusCodeError_1.HttpStatusCodeError(response.status, response.statusText, text, isJson); | ||
} | ||
if (response.status === 204) { | ||
@@ -13,0 +7,0 @@ return undefined; // oof |
{ | ||
"name": "@twurple/api-call", | ||
"version": "5.1.0-pre.3", | ||
"version": "5.1.0-pre.4", | ||
"publishConfig": { | ||
@@ -35,3 +35,3 @@ "access": "public" | ||
"@d-fischer/qs": "^7.0.2", | ||
"@twurple/common": "^5.1.0-pre.3", | ||
"@twurple/common": "^5.1.0-pre.4", | ||
"@types/node-fetch": "^2.5.7", | ||
@@ -51,3 +51,3 @@ "tslib": "^2.0.3" | ||
}, | ||
"gitHead": "6433a8d0b2ffa42b18d70b5074e8129786a640b6" | ||
"gitHead": "06766273bb89c06e25d87b507469a7d30662e12f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17717
350
Updated@twurple/common@^5.1.0-pre.4