Skip to content

Commit

Permalink
emit unknown error
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Jan 10, 2024
1 parent d117f0e commit abb43b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/dwn-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export enum DwnErrorCode {
RecordsReadAuthorizationFailed = 'RecordsReadAuthorizationFailed',
RecordsSubscribeFilterMissingRequiredProperties = 'RecordsSubscribeFilterMissingRequiredProperties',
RecordsSubscribeUnauthorized = 'RecordsSubscribeUnauthorized',
RecordsSubscribeUnknownError = 'RecordsSubscribeUnknownError',
RecordsSchemasDerivationSchemeMissingSchema = 'RecordsSchemasDerivationSchemeMissingSchema',
RecordsValidateIntegrityDelegatedGrantAndIdExistenceMismatch = 'RecordsValidateIntegrityDelegatedGrantAndIdExistenceMismatch',
RecordsValidateIntegrityGrantedToAndSignerMismatch = 'RecordsValidateIntegrityGrantedToAndSignerMismatch',
Expand Down
10 changes: 8 additions & 2 deletions src/handlers/records-subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,14 @@ export class RecordsSubscriptionHandler extends SubscriptionBase {

this.eventEmitter.emit(this.eventChannel, message);
} catch (error) {
//todo: check for known authorization errors, and signal to user there has been an error
this.eventEmitter.emit(this.errorEventChannel, new DwnError(DwnErrorCode.RecordsSubscribeUnauthorized, 'this subscription has become unauthorized'));
const e = error as any;
//todo: add tests and error checking for other authorization errors
if (e.code === DwnErrorCode.ProtocolAuthorizationMissingRole) {
this.eventEmitter.emit(this.errorEventChannel, new DwnError(DwnErrorCode.RecordsSubscribeUnauthorized, 'this subscription has become unauthorized'));
} else {
this.eventEmitter.emit(this.errorEventChannel, new DwnError(DwnErrorCode.RecordsSubscribeUnknownError, 'unknown error occurred, the subscription has been closed'));
}

await this.close();
}
}
Expand Down

0 comments on commit abb43b3

Please sign in to comment.