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