decentralised message store

refactor: response helpers optional header construction

serenity 8b5b62cf 0f510893

Changed files
+11 -1
src
lib
utils
+11 -1
src/lib/utils/http/responses.ts
···
} from "@/lib/types/http/responses";
import { HttpResponseStatusType } from "@/lib/types/http/responses";
-
export const newSuccessResponse = (data: HttpResponseData) => {
+
export interface ResponseOpts {
+
headers: Record<string, string>;
+
}
+
+
export const newSuccessResponse = (
+
data: HttpResponseData,
+
options?: ResponseOpts,
+
) => {
const body: HttpSuccessResponse = {
status: HttpResponseStatusType.SUCCESS,
data,
···
status: 200,
headers: {
"Content-Type": "application/json",
+
...options?.headers,
},
});
};
···
export const newErrorResponse = (
httpCode: number,
errorObj: HttpResponseErrorInfo,
+
options?: ResponseOpts,
) => {
const body: HttpErrorResponse = {
status: HttpResponseStatusType.ERROR,
···
status: httpCode,
headers: {
"Content-Type": "application/json",
+
...options?.headers,
},
});
};