let parcel;
try {
parcel = await Parcel.deserialize(bufferToArray(request.body));
} catch (err) {
// Don't log the full error because 99.99% of the time the reason will suffice.
request.log.info({ reason: (err as Error).message }, 'Refusing malformed parcel');
return reply.code(403).send({ message: 'Payload is not a valid RAMF-serialized parcel' });
}
const parcelAwareLogger = request.log.child({
parcelId: parcel.id,
recipient: parcel.recipient,
senderId: await parcel.senderCertificate.calculateSubjectId(),
});
try {
await fastify.activeEndpoint.validateMessage(parcel);
} catch (err) {
parcelAwareLogger.info({ err }, 'Refusing invalid parcel');
return reply.code(403).send({ message: 'Parcel is well-formed but invalid' });
}
// DECRYPT AND THEN EMIT EVENT (BUT THAT'S PART OF A DIFFERENT ISSUE)
parcelAwareLogger.info('Parcel is valid and has been queued');
return reply.code(202).send({});
This Part 1 of the
POST /
endpoint in the PoHTTP server.Here's an excerpt from the handler, based on the current implementation in Pong and the utility introduced in #21:
See also: