UNPKG

ydb-sdk

Version:

Node.js bindings for working with YDB API over gRPC

47 lines (46 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOperationPayload = getOperationPayload; exports.ensureOperationSucceeded = ensureOperationSucceeded; exports.ensureCallSucceeded = ensureCallSucceeded; const errors_1 = require("../errors"); function getOperationPayload(response) { const { operation } = response; if (operation) { errors_1.YdbError.checkStatus(operation); const value = operation?.result?.value; if (!value) { throw new errors_1.MissingValue('Missing operation result value!'); } return value; } else { throw new errors_1.MissingOperation('No operation in response!'); } } function ensureOperationSucceeded(response, suppressedErrors = []) { try { getOperationPayload(response); } catch (error) { const e = error; if (suppressedErrors.indexOf(e.constructor.status) > -1) { return; } if (!(e instanceof errors_1.MissingValue)) { throw e; } } } function ensureCallSucceeded(response, suppressedErrors = []) { try { errors_1.YdbError.checkStatus(response); } catch (error) { const e = error; if (!(suppressedErrors.indexOf(e.constructor.status) > -1 || e instanceof errors_1.MissingValue)) { throw e; } } return response; }