google-ads-api-client
Version:
A friendly and exhaustive client to the google-ads-api, code generated directly from google's published protobuf schema.
47 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractGoogleAdsApiError = exports.CouldNotExtractGoogleAdsApiError = exports.GoogleAdsApiError = void 0;
const __1 = require("..");
const GrpcError_1 = require("./GrpcError");
class GoogleAdsApiError extends Error {
constructor({ failure }) {
super(`
Google Ads Api has reported the following failure:
${JSON.stringify(failure, (key, value) => (typeof value === 'bigint' ? value.toString() : value), // tell json how to stringify bigints; https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-521460510
2)}
`.trim());
this.failure = failure;
}
}
exports.GoogleAdsApiError = GoogleAdsApiError;
class CouldNotExtractGoogleAdsApiError extends Error {
constructor({ source }) {
super(`
Could not extract a google ads api error from the following source error:
${JSON.stringify(source, (key, value) => (typeof value === 'bigint' ? value.toString() : value), // tell json how to stringify bigints; https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-521460510
2)}
`.trim());
this.source = source;
}
}
exports.CouldNotExtractGoogleAdsApiError = CouldNotExtractGoogleAdsApiError;
/**
* extracts a GoogleAdsError from the error object
*
* note:
* - if its not possible to extract a GoogleAdsError from the input, it will throw a helpful error message
*/
const extractGoogleAdsApiError = (error) => {
// check that its a grcp error; otherwise, no chance
if (!(0, GrpcError_1.isGrpcError)(error))
throw new CouldNotExtractGoogleAdsApiError({ source: error });
// try and grab the failure binary from the grcp error
const googleAdsFailureBin = error.meta?.['google.ads.googleads.v11.errors.googleadsfailure-bin'];
if (!googleAdsFailureBin)
throw new CouldNotExtractGoogleAdsApiError({ source: error });
// decode the failure and cast to GoogleAdsApiError
const failure = __1.GoogleAdsFailure.fromBinary(Uint8Array.from(Buffer.from(googleAdsFailureBin, 'base64')));
return new GoogleAdsApiError({ failure });
};
exports.extractGoogleAdsApiError = extractGoogleAdsApiError;
//# sourceMappingURL=GoogleAdsApiError.js.map