Skip to content
Permalink
Browse files
refactor(error): use error handler everywhere (DEV-475) (#688)
* refactor(error): use error handler everywhere (DEV-475)

* test: fix tests

* refactor(results): remove commented code

* refactor(resource): remove unnecessary asterisks

* test(error): clean up test

* test(error): clean up test
  • Loading branch information
kilchenmann committed Mar 21, 2022
1 parent b4836b8 commit eabfa64dae4a7d7280ff176561ee86ac0adf914b
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 62 deletions.
@@ -68,11 +68,6 @@ describe('ErrorHandlerService', () => {
httpTestingController.verify();
});

afterEach(async () => {
// angular won't call this for us so we need to do it ourselves to avoid leaks.
overlayContainer.ngOnDestroy();
});

it('should be created', () => {
expect(service).toBeTruthy();
});
@@ -3,15 +3,14 @@ import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import { NavigationStart, Router } from '@angular/router';
import { ApiResponseData, ApiResponseError, HealthResponse, KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { Subscription } from 'rxjs';
import { AppInitService } from 'src/app/app-init.service';
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { ComponentCommunicationEventService, Events } from 'src/app/main/services/component-communication-event.service';
import { SearchParams } from 'src/app/workspace/results/list-view/list-view.component';
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { DspConfig } from '../declarations/dsp-config';
import { ErrorHandlerService } from '../error/error-handler.service';
import { NotificationService } from '../services/notification.service';
import { SessionService } from '../services/session.service';

@@ -36,7 +35,6 @@ export class HeaderComponent implements OnInit, OnDestroy {
private _componentCommsService: ComponentCommunicationEventService,
private _dialog: MatDialog,
private _domSanitizer: DomSanitizer,
private _errorHandler: ErrorHandlerService,
private _matIconRegistry: MatIconRegistry,
private _notification: NotificationService,
private _router: Router,
@@ -7,6 +7,7 @@ import { MatMenuModule } from '@angular/material/menu';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTooltipModule } from '@angular/material/tooltip';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import {
ApiResponseError,
@@ -25,9 +26,7 @@ import {
} from '@dasch-swiss/dsp-js';
import { of, Subscription } from 'rxjs';
import { AppInitService } from 'src/app/app-init.service';
import { DspApiConnectionToken, DspAppConfigToken } from 'src/app/main/declarations/dsp-api-tokens';
import { DspAppConfig } from 'src/app/main/declarations/dsp-app-config';
import { TestConfig } from 'test.config';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { DspResource } from '../dsp-resource';
import { IncomingService } from '../services/incoming.service';
import { UserService } from '../services/user.service';
@@ -157,6 +156,7 @@ describe('PropertiesComponent', () => {

TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
ClipboardModule,
MatDialogModule,
MatIconModule,
@@ -4,7 +4,7 @@
<input matInput disabled value="{{ontologiesMetadata.ontologies[0].label}}" class="onto-label">
</mat-form-field>
<mat-form-field *ngIf="ontologiesMetadata.ontologies.length > 1" class="large-field selected-ontologies">
<mat-label>Select a data model *</mat-label>
<mat-label>Select a data model</mat-label>
<mat-select placeholder="Select a data model" formControlName="ontologies" class="select-ontology">
<mat-option *ngFor="let onto of ontologiesMetadata.ontologies" [value]="onto.id">{{ onto.label }}</mat-option>
</mat-select>
@@ -4,7 +4,7 @@
<input matInput disabled value="{{usersProjects[0].shortcode}} | {{usersProjects[0].shortname}}" class="project-label">
</mat-form-field>
<mat-form-field *ngIf="usersProjects.length > 1" class="large-field selected-projects">
<mat-label>Select a project *</mat-label>
<mat-label>Select a project</mat-label>
<mat-select placeholder="Select a project" formControlName="projects" class="select-project">
<mat-option *ngFor="let project of usersProjects" [value]="project.id">
{{ project.shortcode }} | {{ project.shortname }}
@@ -4,7 +4,7 @@
<input matInput disabled value="{{resourceClassDefinitions[0].label}}" class="res-label">
</mat-form-field>
<mat-form-field *ngIf="resourceClassDefinitions.length > 1" class="large-field">
<mat-label>Select a resource *</mat-label>
<mat-label>Select a resource</mat-label>
<mat-select placeholder="Select a resource class" formControlName="resources" class="select-resource">
<mat-option *ngFor="let res of resourceClassDefinitions" [value]="res.id">{{ res.label }}</mat-option>
</mat-select>
@@ -134,7 +134,7 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {
// hide loading indicator

// present error to user
this._notification.openSnackBar(event.error);
this._errorHandler.showMessage(event.error);

}

@@ -1,6 +1,7 @@
import { Component, DebugElement, OnInit, ViewChild } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { MatDialogModule } from '@angular/material/dialog';
import { MatInputModule } from '@angular/material/input';
import { MatMenuModule } from '@angular/material/menu';
import { MatSnackBarModule } from '@angular/material/snack-bar';
@@ -86,11 +87,12 @@ describe('ListValueComponent', () => {
TestHostCreateValueComponent
],
imports: [
ReactiveFormsModule,
BrowserAnimationsModule,
MatDialogModule,
MatInputModule,
MatMenuModule,
MatSnackBarModule,
BrowserAnimationsModule
ReactiveFormsModule,
],
providers: [
{
@@ -13,6 +13,7 @@ import {
import { Subscription } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { BaseValueDirective } from 'src/app/main/directive/base-value.directive';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { NotificationService } from 'src/app/main/services/notification.service';

// https://stackoverflow.com/questions/45661010/dynamic-nested-reactive-form-expressionchangedafterithasbeencheckederror
@@ -44,7 +45,7 @@ export class ListValueComponent extends BaseValueDirective implements OnInit, On
constructor(
@Inject(FormBuilder) private _fb: FormBuilder,
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _notification: NotificationService
private _errorHandler: ErrorHandlerService
) {
super();
}
@@ -76,7 +77,7 @@ export class ListValueComponent extends BaseValueDirective implements OnInit, On
(response2: ListNodeV2) => {
this.listRootNode.children.push(response2);
}, (error: ApiResponseError) => {
this._notification.openSnackBar(error);
this._errorHandler.showMessage(error);
});
}
} else {
@@ -1,9 +1,11 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CountQueryResponse, IFulltextSearchParams, MockResource, ReadResourceSequence, SearchEndpointV2 } from '@dasch-swiss/dsp-js';
import { of } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
@@ -112,7 +114,9 @@ describe('ListViewComponent', () => {
TestResourceListComponent
],
imports: [
BrowserAnimationsModule,
MatButtonModule,
MatDialogModule,
MatIconModule,
MatPaginatorModule,
MatSnackBarModule
@@ -2,6 +2,7 @@ import { Component, EventEmitter, Inject, Input, OnChanges, Output } from '@angu
import { PageEvent } from '@angular/material/paginator';
import { ApiResponseError, CountQueryResponse, IFulltextSearchParams, KnoraApiConnection, ReadResourceSequence } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service';
import { NotificationService } from 'src/app/main/services/notification.service';

@@ -116,8 +117,9 @@ export class ListViewComponent implements OnChanges {

constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _notification: NotificationService,
private _componentCommsService: ComponentCommunicationEventService,
private _errorHandler: ErrorHandlerService,
private _notification: NotificationService
) { }

ngOnChanges(): void {
@@ -148,18 +150,15 @@ export class ListViewComponent implements OnChanges {
} else if (res.count > 0) {
this.selectedResourceIdx = res.resListIndex;
this.selectedResources.emit(res);
this.resourceSelected.emit(res.resInfo[0].id);
}


}

goToPage(page: PageEvent) {
this.pageEvent = page;
this._doSearch();
}


/**
* do the search and send the resources to the child components
* like resource-list, resource-grid or resource-table
@@ -183,7 +182,7 @@ export class ListViewComponent implements OnChanges {
}
},
(countError: ApiResponseError) => {
this._notification.openSnackBar(countError);
this._errorHandler.showMessage(countError);
}
);
}
@@ -200,7 +199,7 @@ export class ListViewComponent implements OnChanges {
this.loading = false;
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this._errorHandler.showMessage(error);
this.resources = undefined;
this.loading = false;
}
@@ -224,7 +223,7 @@ export class ListViewComponent implements OnChanges {
}
},
(countError: ApiResponseError) => {
this._notification.openSnackBar(countError);
this._errorHandler.showMessage(countError);
}
);
}
@@ -246,13 +245,13 @@ export class ListViewComponent implements OnChanges {
this.loading = false;
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this._errorHandler.showMessage(error);
this.resources = undefined;
this.loading = false;
}
);
} else {
console.error('The gravsearch query is not set correctly');
this._notification.openSnackBar('The gravsearch query is not set correctly');
this.resources = undefined;
this.loading = false;
}
@@ -3,6 +3,7 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { By } from '@angular/platform-browser';
@@ -92,6 +93,7 @@ describe('AdvancedSearchComponent', () => {
imports: [
ReactiveFormsModule,
BrowserAnimationsModule,
MatDialogModule,
MatIconModule,
MatSnackBarModule
],
@@ -13,11 +13,11 @@ import { FormBuilder, FormGroup } from '@angular/forms';
import { ApiResponseError, Constants, KnoraApiConnection, OntologiesMetadata, OntologyMetadata } from '@dasch-swiss/dsp-js';
import { Subscription } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { NotificationService } from 'src/app/main/services/notification.service';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { SearchParams } from '../../results/list-view/list-view.component';
import { GravsearchGenerationService } from '../services/gravsearch-generation.service';
import { PropertyWithValue } from './resource-and-property-selection/search-select-property/specify-property-value/operator';
import { ResourceAndPropertySelectionComponent } from './resource-and-property-selection/resource-and-property-selection.component';
import { PropertyWithValue } from './resource-and-property-selection/search-select-property/specify-property-value/operator';

@Component({
selector: 'app-advanced-search',
@@ -58,11 +58,11 @@ export class AdvancedSearchComponent implements OnInit, OnDestroy, AfterViewChec
errorMessage: ApiResponseError;

constructor(
@Inject(FormBuilder) private _fb: FormBuilder,
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _notification: NotificationService,
private _gravsearchGenerationService: GravsearchGenerationService) {
}
@Inject(FormBuilder) private _fb: FormBuilder,
private _errorHandler: ErrorHandlerService,
private _gravsearchGenerationService: GravsearchGenerationService
) { }

ngOnInit() {

@@ -105,7 +105,7 @@ export class AdvancedSearchComponent implements OnInit, OnDestroy, AfterViewChec

},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this._errorHandler.showMessage(error);
this.errorMessage = error;
});
} else {
@@ -120,7 +120,7 @@ export class AdvancedSearchComponent implements OnInit, OnDestroy, AfterViewChec

},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this._errorHandler.showMessage(error);
this.errorMessage = error;
});
}
@@ -1,9 +1,10 @@
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { Component, EventEmitter, Inject, Input, OnInit, Output, ViewChild } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { MatButtonHarness } from '@angular/material/button/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatInputModule } from '@angular/material/input';
import { MatMenu, MatMenuModule } from '@angular/material/menu';
import { MatSnackBarModule } from '@angular/material/snack-bar';
@@ -80,10 +81,11 @@ describe('SearchListValueComponent', () => {
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
ReactiveFormsModule,
MatDialogModule,
MatInputModule,
MatMenuModule,
MatSnackBarModule
MatSnackBarModule,
ReactiveFormsModule
],
declarations: [
SearchListValueComponent,
@@ -9,7 +9,7 @@ import {
ResourcePropertyDefinition
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { NotificationService } from 'src/app/main/services/notification.service';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { IRI, PropertyValue, Value } from '../operator';

// https://stackoverflow.com/questions/45661010/dynamic-nested-reactive-form-expressionchangedafterithasbeencheckederror
@@ -39,8 +39,8 @@ export class SearchListValueComponent implements OnInit, OnDestroy, PropertyValu

constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _notification: NotificationService,
@Inject(FormBuilder) private _fb: FormBuilder
@Inject(FormBuilder) private _fb: FormBuilder,
private _errorHandler: ErrorHandlerService
) {
}

@@ -62,7 +62,7 @@ export class SearchListValueComponent implements OnInit, OnDestroy, PropertyValu
this.listRootNode = response;
},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this._errorHandler.showMessage(error);
}
);

@@ -1,6 +1,7 @@
import { Component, DebugElement, OnInit, ViewChild } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatDialogModule } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { By } from '@angular/platform-browser';
@@ -53,11 +54,12 @@ describe('ExpertSearchComponent', () => {
TestHostComponent
],
imports: [
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
FormsModule,
MatDialogModule,
MatFormFieldModule,
MatInputModule
MatInputModule,
ReactiveFormsModule
],
providers: [
{

0 comments on commit eabfa64

Please sign in to comment.