Skip to content

Commit

Permalink
refactor(error): use error handler everywhere (DEV-475) (#688)
Browse files Browse the repository at this point in the history
* 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 eabfa64
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 62 deletions.
5 changes: 0 additions & 5 deletions src/app/main/error/error-handler.service.spec.ts
Expand Up @@ -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();
});
Expand Down
4 changes: 1 addition & 3 deletions src/app/main/header/header.component.ts
Expand Up @@ -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';

Expand All @@ -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,
Expand Down
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -157,6 +156,7 @@ describe('PropertiesComponent', () => {

TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
ClipboardModule,
MatDialogModule,
MatIconModule,
Expand Down
Expand Up @@ -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>
Expand Down
Expand Up @@ -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 }}
Expand Down
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/app/workspace/resource/resource.component.ts
Expand Up @@ -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);

}

Expand Down
@@ -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';
Expand Down Expand Up @@ -86,11 +87,12 @@ describe('ListValueComponent', () => {
TestHostCreateValueComponent
],
imports: [
ReactiveFormsModule,
BrowserAnimationsModule,
MatDialogModule,
MatInputModule,
MatMenuModule,
MatSnackBarModule,
BrowserAnimationsModule
ReactiveFormsModule,
],
providers: [
{
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand Down
@@ -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';
Expand Down Expand Up @@ -112,7 +114,9 @@ describe('ListViewComponent', () => {
TestResourceListComponent
],
imports: [
BrowserAnimationsModule,
MatButtonModule,
MatDialogModule,
MatIconModule,
MatPaginatorModule,
MatSnackBarModule
Expand Down
17 changes: 8 additions & 9 deletions src/app/workspace/results/list-view/list-view.component.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -183,7 +182,7 @@ export class ListViewComponent implements OnChanges {
}
},
(countError: ApiResponseError) => {
this._notification.openSnackBar(countError);
this._errorHandler.showMessage(countError);
}
);
}
Expand All @@ -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;
}
Expand All @@ -224,7 +223,7 @@ export class ListViewComponent implements OnChanges {
}
},
(countError: ApiResponseError) => {
this._notification.openSnackBar(countError);
this._errorHandler.showMessage(countError);
}
);
}
Expand All @@ -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;
}
Expand Down
Expand Up @@ -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';
Expand Down Expand Up @@ -92,6 +93,7 @@ describe('AdvancedSearchComponent', () => {
imports: [
ReactiveFormsModule,
BrowserAnimationsModule,
MatDialogModule,
MatIconModule,
MatSnackBarModule
],
Expand Down
Expand Up @@ -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',
Expand Down Expand Up @@ -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() {

Expand Down Expand Up @@ -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 {
Expand All @@ -120,7 +120,7 @@ export class AdvancedSearchComponent implements OnInit, OnDestroy, AfterViewChec

},
(error: ApiResponseError) => {
this._notification.openSnackBar(error);
this._errorHandler.showMessage(error);
this.errorMessage = error;
});
}
Expand Down
@@ -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';
Expand Down Expand Up @@ -80,10 +81,11 @@ describe('SearchListValueComponent', () => {
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
ReactiveFormsModule,
MatDialogModule,
MatInputModule,
MatMenuModule,
MatSnackBarModule
MatSnackBarModule,
ReactiveFormsModule
],
declarations: [
SearchListValueComponent,
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
) {
}

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

Expand Down
@@ -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';
Expand Down Expand Up @@ -53,11 +54,12 @@ describe('ExpertSearchComponent', () => {
TestHostComponent
],
imports: [
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
FormsModule,
MatDialogModule,
MatFormFieldModule,
MatInputModule
MatInputModule,
ReactiveFormsModule
],
providers: [
{
Expand Down

0 comments on commit eabfa64

Please sign in to comment.