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

Commit c154d3f

Browse files
committed
Handle publisher errors
1 parent 417c2a7 commit c154d3f

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

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

1212
node {

src/app/channels/channel-main/channel-main.component.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PublisherService } from 'src/app/shared/publisher.service';
66
import { MatSnackBar } from '@angular/material/snack-bar';
77
import { Operation } from 'src/app/shared/models/channel.model';
88
import { Subscription } from 'rxjs';
9+
import { STATUS } from 'angular-in-memory-web-api';
910

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

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

67+
private handlePublishSuccess() {
68+
return this.snackBar.open('Example payload sent to: ' + this.channelName, 'PUBLISHED', {
69+
duration: 3000
70+
});
71+
}
72+
73+
private handlePublishError(err: {status?: number}) {
74+
let msg = 'Publish failed';
75+
if (err?.status === STATUS.NOT_FOUND) {
76+
msg += ': no publisher was provided for ' + this.protocolName;
77+
}
78+
79+
return this.snackBar.open(msg, 'ERROR', {
80+
duration: 4000
81+
});
82+
}
83+
6784
}

src/app/shared/mock-server.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,17 @@ export class MockServer implements InMemoryDbService {
1919

2020
return undefined;
2121
}
22+
23+
post(reqInfo: RequestInfo) {
24+
if (reqInfo.req.url.endsWith('/publish')) {
25+
return reqInfo.utils.createResponse$(() => {
26+
return {
27+
status: STATUS.OK
28+
}
29+
})
30+
}
31+
32+
return undefined;
33+
}
34+
2235
}

0 commit comments

Comments
 (0)