UNPKG

aws-delivlib

Version:

A fabulous library for defining continuous pipelines for building, testing and releasing code libraries.

31 lines (30 loc) 923 B
import AggregateError from "aggregate-error"; function getPayload(request) { if (request.body) { if (typeof request.body !== "string") { console.warn( "[@octokit/webhooks] Passing the payload as a JSON object in `request.body` is deprecated and will be removed in a future release of `@octokit/webhooks`, please pass it as a a `string` instead." ); } return Promise.resolve(request.body); } return new Promise((resolve, reject) => { let data = ""; request.setEncoding("utf8"); request.on("error", (error) => reject(new AggregateError([error]))); request.on("data", (chunk) => data += chunk); request.on("end", () => { try { JSON.parse(data); resolve(data); } catch (error) { error.message = "Invalid JSON"; error.status = 400; reject(new AggregateError([error])); } }); }); } export { getPayload };