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 createHandlerWithError(
serviceName: string,
statusCode: number
): HandlerType {
return rest.post(createMask(serviceName), (_, res, ctx) => {
return res(
ctx.status(200),
ctx.set({
"content-length": "0",
"content-type": "application/grpc-web+proto",
"grpc-message": "Error Message",
"grpc-status": `${statusCode}`,
})
);
});
}
export function createHandler(
serviceName: string,
getResponseMessage: (requestData: Uint8Array) => T
): HandlerType {
return rest.post(
createMask(serviceName),
(req, res, ctx) => {
const arr: Uint8Array =
typeof req.body === "string" ? encoder.encode(req.body) : req.body;
const message = getResponseMessage(arr.slice(5));
const data = serialize(message.serializeBinary());
return res(
ctx.status(200),
ctx.set("Content-Type", "application/grpc-web+proto"),
ctx.body(data)
);
}
);
}
import { rest } from "msw";
import { serialize } from "./serializer";
import { createMask } from "./utils";
const DummyHandler = rest.post("", (_0, res, ctx) => {
return res(ctx.status(200));
});
type HandlerType = typeof DummyHandler;
const encoder = new TextEncoder();
export function createHandler(
serviceName: string,
getResponseMessage: (requestData: Uint8Array) => T
): HandlerType {
return rest.post(
createMask(serviceName),
(req, res, ctx) => {
const arr: Uint8Array =
typeof req.body === "string" ? encoder.encode(req.body) : req.body;