"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const request_1 = require("request");
const BackoffError_1 = require("./BackoffError");
class RequestRequestHandler {
    constructor({ backoffHTTPCode = 429, } = {}) {
        this.backoffHTTPCode = backoffHTTPCode;
    }
    // simple promise wrapper for executing a request using the 
    // request libary
    async request(requestConfig) {
        return new Promise((resolve, reject) => {
            (0, request_1.default)(requestConfig, (err, response, body) => {
                if (err) {
                    reject(err);
                }
                else if (response.statusCode === this.backoffHTTPCode) {
                    reject(new BackoffError_1.default(`The request returned the status ${this.backoffHTTPCode}. Need to back off!`));
                }
                else {
                    resolve(response);
                }
            });
        });
    }
}
exports.default = RequestRequestHandler;
//# sourceMappingURL=RequestRequestHandler.js.map