mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-15 18:31:56 +00:00
Merge pull request #14 from avatao-content/error_handling
Implement robust error handling
This commit is contained in:
commit
10cf9907d2
@ -1,4 +1,5 @@
|
||||
export class ProcessCommand {
|
||||
command: string;
|
||||
process_name: string;
|
||||
error?: string;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
|
||||
import { WebSocketService } from './websocket.service';
|
||||
import { ProcessCommand } from './processcommand';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { WSMessage } from './wsmessage';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@ -16,9 +17,17 @@ export class ProcessManagerService {
|
||||
this.webSocketService.connect();
|
||||
}
|
||||
|
||||
subscribeCallback(process_name: string, callback: (event: any) => void) {
|
||||
this.webSocketService.observeKey<ProcessCommand>(this.key)
|
||||
.pipe(filter(message => message.data.process_name === process_name)).subscribe(callback);
|
||||
subscribeCallback(process_name: string, callback: (event: WSMessage<ProcessCommand>) => void) {
|
||||
this.observeProcessMessage(process_name).subscribe(callback);
|
||||
}
|
||||
|
||||
subscribeErrorCallback(process_name: string, callback: (event: WSMessage<ProcessCommand>) => void) {
|
||||
this.observeProcessMessage(process_name).pipe(filter(message => 'error' in message.data)).subscribe(callback);
|
||||
}
|
||||
|
||||
observeProcessMessage(process_name: string) {
|
||||
return this.webSocketService.observeKey<ProcessCommand>(this.key)
|
||||
.pipe(filter(message => message.data.process_name === process_name));
|
||||
}
|
||||
|
||||
sendCommand(command: string, process_name: string) {
|
||||
|
@ -27,7 +27,9 @@
|
||||
[class.btn-success]="deployButtonState === 'DEPLOYED'"
|
||||
[class.btn-info]="deployButtonState === 'DEPLOYING'"
|
||||
[class.disabled]="deployButtonState === 'DEPLOYING' || deployButtonState === 'DEPLOYED'"
|
||||
[class.btn-danger]="deployButtonState === 'FAILED'"
|
||||
><span *ngIf="deployButtonState === 'TODEPLOY'">Deploy</span>
|
||||
<span *ngIf="deployButtonState === 'DEPLOYED'">Deploy</span>
|
||||
<span *ngIf="deployButtonState === 'DEPLOYING'"><div class="loader"></div>Reloading app...</span></button>
|
||||
<span *ngIf="deployButtonState === 'DEPLOYING'"><div class="loader"></div>Reloading app...</span>
|
||||
<span *ngIf="deployButtonState === 'FAILED'">Deployment failed</span></button>
|
||||
</div>
|
||||
|
@ -51,6 +51,7 @@ export class WebideComponent implements OnInit {
|
||||
this.requestCode();
|
||||
this.processManagerService.init();
|
||||
this.processManagerService.subscribeCallback('login', (event) => { this.setDeployButtonState('DEPLOYED'); });
|
||||
this.processManagerService.subscribeErrorCallback('login', (event) => { this.setDeployButtonState('FAILED'); });
|
||||
this.resetAutoSaveCountdown();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user