mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Wrap createConnectionForState/ensureGrant in a try/catch (#680)
* Fix thrown exception when the state is not granted * changelog * make it an error * Typing
This commit is contained in:
parent
6c4bbc7150
commit
037674115a
1
changelog.d/680.bugfix
Normal file
1
changelog.d/680.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix a missing grant for a connection sometimes causing a crash.
|
@ -173,7 +173,7 @@ export class ConnectionManager extends EventEmitter {
|
||||
* @param rollbackBadState
|
||||
* @returns
|
||||
*/
|
||||
public async createConnectionForState(roomId: string, state: StateEvent<any>, rollbackBadState: boolean) {
|
||||
public async createConnectionForState(roomId: string, state: StateEvent<any>, rollbackBadState: boolean): Promise<IConnection|undefined> {
|
||||
// Empty object == redacted
|
||||
if (state.content.disabled === true || Object.keys(state.content).length === 0) {
|
||||
log.debug(`${roomId} has disabled state for ${state.type}`);
|
||||
@ -195,20 +195,24 @@ export class ConnectionManager extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
const connection = await connectionType.createConnectionForState(roomId, state, {
|
||||
as: this.as,
|
||||
intent: botUser.intent,
|
||||
config: this.config,
|
||||
tokenStore: this.tokenStore,
|
||||
commentProcessor: this.commentProcessor,
|
||||
messageClient: this.messageClient,
|
||||
storage: this.storage,
|
||||
github: this.github,
|
||||
});
|
||||
|
||||
// Finally, ensure the connection is allowed by us.
|
||||
await connection.ensureGrant?.(state.sender);
|
||||
return connection;
|
||||
try {
|
||||
const connection = await connectionType.createConnectionForState(roomId, state, {
|
||||
as: this.as,
|
||||
intent: botUser.intent,
|
||||
config: this.config,
|
||||
tokenStore: this.tokenStore,
|
||||
commentProcessor: this.commentProcessor,
|
||||
messageClient: this.messageClient,
|
||||
storage: this.storage,
|
||||
github: this.github,
|
||||
});
|
||||
// Finally, ensure the connection is allowed by us.
|
||||
await connection.ensureGrant?.(state.sender);
|
||||
return connection;
|
||||
} catch (ex) {
|
||||
log.error(`Not creating connection for state ${roomId}/${state.type}`, ex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user