Skip to content

Commit

Permalink
Fix WebChat get attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-joelmut authored and johnataylor committed Feb 28, 2023
1 parent 8300f37 commit a957645
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export function createGetAttachmentHandler(state: DLServerState) {
buffer = Buffer.from(attachmentBase64.toString(), 'base64');
}

res.type(attachment.type);
res.send(StatusCodes.OK, buffer);
res.status(StatusCodes.OK).type(attachment.type).send(buffer);
} else {
handleDirectLineErrors(req, res, {
status: StatusCodes.NOT_FOUND,
Expand Down
8 changes: 5 additions & 3 deletions Composer/packages/server/src/middleware/logNetworkTraffic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ export function logNetworkTraffic(req: Request, res: Response, next?: NextFuncti
// when the request finishes, log the payload and status code to the client
res.once('finish', () => {
let data: ConversationNetworkErrorItem | ConversationNetworkTrafficItem | undefined;
let payload = (res as any).sentData;
payload = typeof payload === 'string' ? JSON.parse(payload || '{}') : payload;
if (res.statusCode >= 400) {
// an error was sent to the client
const { error = {} } = JSON.parse((res as any).sentData || '{}');
const { error = {} } = payload;
data = {
error: {
details: error.details,
Expand All @@ -29,7 +31,7 @@ export function logNetworkTraffic(req: Request, res: Response, next?: NextFuncti
id: uuid(),
request: { method: req.method, payload: req.body, route: req.originalUrl },
response: {
payload: JSON.parse((res as any).sentData || '{}'),
payload,
statusCode: res.statusCode,
},
timestamp: Date.now(),
Expand All @@ -41,7 +43,7 @@ export function logNetworkTraffic(req: Request, res: Response, next?: NextFuncti
id: uuid(),
request: { method: req.method, payload: req.body, route: req.originalUrl },
response: {
payload: JSON.parse((res as any).sentData || '{}'),
payload,
statusCode: res.statusCode,
},
timestamp: Date.now(),
Expand Down

0 comments on commit a957645

Please sign in to comment.