Skip to content

Commit

Permalink
fix: Update channelServiceRoutes to add next() parameter to support r…
Browse files Browse the repository at this point in the history
…estify 10.0.0+ (#4429)

* Add next callback to support restify chain handler

* Update next type and channelServiceRoutes tests

* Remove return next() to fix Headers Sent Error

* Add return next() in the handler function
  • Loading branch information
Anish Prasad authored and Tracy Boehrer committed Mar 21, 2023
1 parent a1dd21b commit 67504ee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 42 deletions.
39 changes: 26 additions & 13 deletions libraries/botbuilder/src/channelServiceRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processSendToConversation(req: WebRequest, res: WebResponse): void {
private processSendToConversation(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
ChannelServiceRoutes.readActivity(req)
.then((activity) => {
Expand All @@ -92,6 +92,7 @@ export class ChannelServiceRoutes {
res.send(resourceResponse);
}
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -105,7 +106,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processReplyToActivity(req: WebRequest, res: WebResponse): void {
private processReplyToActivity(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
ChannelServiceRoutes.readActivity(req)
.then((activity) => {
Expand All @@ -117,6 +118,7 @@ export class ChannelServiceRoutes {
res.send(resourceResponse);
}
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -130,7 +132,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processUpdateActivity(req: WebRequest, res: WebResponse): void {
private processUpdateActivity(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
ChannelServiceRoutes.readActivity(req)
.then((activity) => {
Expand All @@ -142,6 +144,7 @@ export class ChannelServiceRoutes {
res.send(resourceResponse);
}
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -155,13 +158,14 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processDeleteActivity(req: WebRequest, res: WebResponse): void {
private processDeleteActivity(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
this.channelServiceHandler
.handleDeleteActivity(authHeader, req.params.conversationId, req.params.activityId)
.then(() => {
res.status(200);
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -171,7 +175,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processGetActivityMembers(req: WebRequest, res: WebResponse): void {
private processGetActivityMembers(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
this.channelServiceHandler
.handleGetActivityMembers(authHeader, req.params.conversationId, req.params.activityId)
Expand All @@ -181,6 +185,7 @@ export class ChannelServiceRoutes {
}
res.status(200);
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -190,7 +195,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processCreateConversation(req: WebRequest, res: WebResponse): void {
private processCreateConversation(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
ChannelServiceRoutes.readBody<ConversationParameters>(req).then((conversationParameters) => {
this.channelServiceHandler
Expand All @@ -201,6 +206,7 @@ export class ChannelServiceRoutes {
}
res.status(201);
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -211,7 +217,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processGetConversations(req: WebRequest, res: WebResponse): void {
private processGetConversations(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
this.channelServiceHandler
.handleGetConversations(authHeader, req.params.conversationId, req.query.continuationToken)
Expand All @@ -221,6 +227,7 @@ export class ChannelServiceRoutes {
}
res.status(200);
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -230,7 +237,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processGetConversationMembers(req: WebRequest, res: WebResponse): void {
private processGetConversationMembers(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
this.channelServiceHandler
.handleGetConversationMembers(authHeader, req.params.conversationId)
Expand All @@ -240,6 +247,7 @@ export class ChannelServiceRoutes {
res.send(channelAccounts);
}
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -249,7 +257,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processGetConversationMember(req: WebRequest, res: WebResponse): void {
private processGetConversationMember(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
this.channelServiceHandler
.handleGetConversationMember(authHeader, req.params.memberId, req.params.conversationId)
Expand All @@ -259,6 +267,7 @@ export class ChannelServiceRoutes {
res.send(channelAccount);
}
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -268,7 +277,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processGetConversationPagedMembers(req: WebRequest, res: WebResponse): void {
private processGetConversationPagedMembers(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
let pageSize = parseInt(req.query.pageSize);
if (isNaN(pageSize)) {
Expand All @@ -287,6 +296,7 @@ export class ChannelServiceRoutes {
res.send(pagedMembersResult);
}
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -296,13 +306,14 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processDeleteConversationMember(req: WebRequest, res: WebResponse): void {
private processDeleteConversationMember(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
this.channelServiceHandler
.handleDeleteConversationMember(authHeader, req.params.conversationId, req.params.memberId)
.then(() => {
res.status(200);
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -312,7 +323,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processSendConversationHistory(req: WebRequest, res: WebResponse): void {
private processSendConversationHistory(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
ChannelServiceRoutes.readBody<Transcript>(req)
.then((transcript) => {
Expand All @@ -324,6 +335,7 @@ export class ChannelServiceRoutes {
}
res.status(200);
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand All @@ -337,7 +349,7 @@ export class ChannelServiceRoutes {
/**
* @private
*/
private processUploadAttachment(req: WebRequest, res: WebResponse): void {
private processUploadAttachment(req: WebRequest, res: WebResponse, next: Function): void {
const authHeader = req.headers.authorization || req.headers.Authorization || '';
ChannelServiceRoutes.readBody<AttachmentData>(req)
.then((attachmentData) => {
Expand All @@ -349,6 +361,7 @@ export class ChannelServiceRoutes {
}
res.status(200);
res.end();
return next();
})
.catch((err) => {
ChannelServiceRoutes.handleError(err, res);
Expand Down
Loading

0 comments on commit 67504ee

Please sign in to comment.