Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
Handle publisher errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stavshamir committed Nov 25, 2021
1 parent 417c2a7 commit c154d3f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'io.github.springwolf'
version = '0.3.0' + (Boolean.valueOf(System.getProperty('snapshot')) ? '-SNAPSHOT' : '')
version = '0.3.1' + (Boolean.valueOf(System.getProperty('snapshot')) ? '-SNAPSHOT' : '')
sourceCompatibility = '1.8'

node {
Expand Down
23 changes: 20 additions & 3 deletions src/app/channels/channel-main/channel-main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PublisherService } from 'src/app/shared/publisher.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Operation } from 'src/app/shared/models/channel.model';
import { Subscription } from 'rxjs';
import { STATUS } from 'angular-in-memory-web-api';

@Component({
selector: 'app-channel-main',
Expand Down Expand Up @@ -53,9 +54,8 @@ export class ChannelMainComponent implements OnInit {
const json = JSON.parse(example);

this.publisherService.publish(this.protocolName, this.channelName, json).subscribe(
_ => this.snackBar.open('Example payload sent to: ' + this.channelName, 'PUBLISHED', {
duration: 3000
})
_ => this.handlePublishSuccess(),
err => this.handlePublishError(err)
);
} catch(error) {
this.snackBar.open('Example payload is not valid', 'ERROR', {
Expand All @@ -64,4 +64,21 @@ export class ChannelMainComponent implements OnInit {
}
}

private handlePublishSuccess() {
return this.snackBar.open('Example payload sent to: ' + this.channelName, 'PUBLISHED', {
duration: 3000
});
}

private handlePublishError(err: {status?: number}) {
let msg = 'Publish failed';
if (err?.status === STATUS.NOT_FOUND) {
msg += ': no publisher was provided for ' + this.protocolName;
}

return this.snackBar.open(msg, 'ERROR', {
duration: 4000
});
}

}
13 changes: 13 additions & 0 deletions src/app/shared/mock-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@ export class MockServer implements InMemoryDbService {

return undefined;
}

post(reqInfo: RequestInfo) {
if (reqInfo.req.url.endsWith('/publish')) {
return reqInfo.utils.createResponse$(() => {
return {
status: STATUS.OK
}
})
}

return undefined;
}

}

0 comments on commit c154d3f

Please sign in to comment.