Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createResponse(
payload: Buffer | string | any | null,
code: MessageCode = MessageCodes.success.content,
contentFormat: ContentFormats = ContentFormats.application_json,
): CoapResponse {
if (!(payload instanceof Buffer)) {
if (typeof payload !== "string" && typeof payload !== "undefined") {
payload = JSON.stringify(payload);
}
}
return {
code,
format: contentFormat,
payload: payload != null ?
payload instanceof Buffer ? payload :
Buffer.from(payload, "utf8") : undefined,
};
}
export function createErrorResponse(code: MessageCode = MessageCodes.clientError.notFound): CoapResponse {