firebase-tools
Version:
Command-Line Interface for Firebase
49 lines (48 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSampleCrash = void 0;
const apiv2_1 = require("../apiv2");
const logger_1 = require("../logger");
const error_1 = require("../error");
const api_1 = require("../api");
const TIMEOUT = 10000;
const apiClient = new apiv2_1.Client({
urlPrefix: (0, api_1.crashlyticsApiOrigin)(),
apiVersion: "v1alpha",
});
async function getSampleCrash(appId, issueId, sampleCount, variantId) {
try {
const queryParams = new URLSearchParams();
queryParams.set("filter.issue.id", issueId);
queryParams.set("page_size", String(sampleCount));
if (variantId) {
queryParams.set("filter.issue.variant_id", variantId);
}
const requestProjectNumber = parseProjectNumber(appId);
if (requestProjectNumber === undefined) {
throw new error_1.FirebaseError("Unable to get the projectId from the AppId.");
}
const response = await apiClient.request({
method: "GET",
headers: {
"Content-Type": "application/json",
},
path: `/projects/${requestProjectNumber}/apps/${appId}/events`,
queryParams: queryParams,
timeout: TIMEOUT,
});
return response.body;
}
catch (err) {
logger_1.logger.debug(err.message);
throw new error_1.FirebaseError(`Failed to fetch the same crash for the Firebase AppId ${appId}, IssueId ${issueId}. Error: ${err}.`, { original: err });
}
}
exports.getSampleCrash = getSampleCrash;
function parseProjectNumber(appId) {
const appIdParts = appId.split(":");
if (appIdParts.length > 1) {
return appIdParts[1];
}
return undefined;
}