import { Component , OnDestroy , OnInit } from '@angular/core' ; import { DebugService } from './debug.service' ; import { BackendHttpError } from '../error/models/custom.error' ; import { FormControl , FormGroup , Validators } from '@angular/forms' ; import { Subscription } from 'rxjs' ; @ Component ( { selector : 'cmdb-debug' , templateUrl : './debug.component.html' , styleUrls : [ './debug.component.scss' ] } ) export class DebugComponent implements OnInit , OnDestroy { private httpResponseSubscription : Subscription ; private customHttpResponseSubscription : Subscription ; public customResponse : BackendHttpError = null ; public customResponseForm : FormGroup ; public constructor ( private debugService ) { this . httpResponseSubscription = new Subscription ( ) ; this . customHttpResponseSubscription = new Subscription ( ) ; } public ngOnInit ( ) { this . customResponseForm = new FormGroup ( { customStatus : new FormControl ( 400 , Validators . required ) , customMessage : new FormControl ( '' ) } ) ; } public onStartHttpResponse ( statusCode ) { this . debugService . getResponse ( statusCode ) . subscribe ( resp => { } , ( error ) => { document . getElementById ( `http_${ statusCode }_response` ) . innerHTML = error . error . description ; } ) ; } public onCustomResponse ( ) { if ( this . customResponseForm . valid ) { this . debugService . getResponseWithMessage ( this . customResponseForm . get ( 'customStatus' ) . value , this . customResponseForm . get ( 'customMessage' ) . value ) . subscribe ( ( ) => { } , ( error ) => { this . customResponse = error . error as BackendHttpError ; } ) ; } } public ngOnDestroy ( ) { this . httpResponseSubscription . unsubscribe ( ) ; this . customHttpResponseSubscription . unsubscribe ( ) ; } }