Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const setKoaResponse = (response: SidetreeResponseModel, koaResponse: Koa.Response) => {
koaResponse.status = SidetreeResponse.toHttpStatus(response.status);
if (response.body) {
koaResponse.set('Content-Type', 'application/json');
koaResponse.body = response.body;
} else {
// Need to set the body explicitly to empty string, else koa will echo the request as the response.
koaResponse.body = '';
}
};
const setKoaResponse = (response: SidetreeResponseModel, koaResponse: Koa.Response, contentType?: string) => {
koaResponse.status = SidetreeResponse.toHttpStatus(response.status);
if (contentType) {
koaResponse.set('Content-Type', contentType);
} else {
koaResponse.set('Content-Type', 'application/json');
}
if (response.body) {
koaResponse.body = response.body;
} else {
// Need to set the body explicitly, otherwise Koa will return HTTP 204.
koaResponse.body = '';
}
};