Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp
611 B
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later

import {MimeType} from '@fluxer/constants/src/HttpConstants';

interface JsonErrorResponseOptions {
	status: number;
	code: string;
	message: string;
	data?: Record<string, unknown>;
	headers?: Record<string, string>;
}

export function createJsonErrorResponse(options: JsonErrorResponseOptions): Response {
	return new Response(
		JSON.stringify({
			code: options.code,
			message: options.message,
			...(options.data ?? {}),
		}),
		{
			status: options.status,
			headers: {
				'Content-Type': MimeType.JSON,
				...(options.headers ?? {}),
			},
		},
	);
}