How to use the node-coap-client/build/Message.MessageCodes.success function in node-coap-client

To help you get started, we’ve selected a few node-coap-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AlCalzone / node-tradfri-client / test / mocks.ts View on Github external
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 {