UNPKG

@qualifyze/airtable

Version:
36 lines 1.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.OfficialClientWrapper = void 0; const airtable_1 = __importDefault(require("airtable")); const error_1 = require("./error"); class OfficialClientWrapper { constructor(airtable) { this.officialClient = airtable; } async runAction(method, { path, payload }) { try { const { statusCode, headers, body } = await this.officialClient.makeRequest({ method, path: path === null ? undefined : `/${path}`, qs: payload?.query, body: payload?.body, }); if (!(+statusCode >= 200 && +statusCode < 300)) { throw new Error(`Airtable API responded with status code "${statusCode}, but no semantic error in response: ${JSON.stringify({ headers, body }, null, 2)}`); } return body; } catch (err) { // Because official client error is not extended from Error so no stack trace if (err instanceof airtable_1.default.Error) { throw error_1.AirtableError.fromOfficialClientError(err); } throw err; } } } exports.OfficialClientWrapper = OfficialClientWrapper; //# sourceMappingURL=official-client-wrapper.js.map