forked from rero/rero-ils-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement new handle error service
* Implements the new handle error service. * Personalizes the error message for the document import. * Closes rero/rero-ils#3564. Co-Authored-by: Bertrand Zuchuat <[email protected]>
- Loading branch information
1 parent
2b1206b
commit c10e944
Showing
4 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
projects/admin/src/app/service/record.handle-error.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* RERO ILS UI | ||
* Copyright (C) 2020-2023 RERO | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { HttpErrorResponse } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { RecordHandleErrorService as CoreRecordHandleErrorService } from '@rero/ng-core'; | ||
import { NgxSpinnerService } from 'ngx-spinner'; | ||
import { ToastrService } from 'ngx-toastr'; | ||
import { NEVER, Observable } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class RecordHandleErrorService extends CoreRecordHandleErrorService { | ||
|
||
/** | ||
* Constructor | ||
* @param translateService - TranslateService | ||
* @param toastrService - ToastrService | ||
* @param spinner - NgxSpinnerService | ||
*/ | ||
constructor( | ||
protected translateService: TranslateService, | ||
private toastrService: ToastrService, | ||
private spinner: NgxSpinnerService | ||
) { | ||
super(translateService); | ||
} | ||
|
||
/** | ||
* Http handle Error | ||
* @param error - Http Error Response | ||
* @param resourceName - Resource name | ||
* @returns Observable | ||
*/ | ||
handleError(error: HttpErrorResponse, resourceName?: string): Observable<never> { | ||
if (resourceName.startsWith('import_')) { | ||
this.toastrService.error( | ||
this.translateService.instant( | ||
'Your request to the external server has failed. Try again later ({{ statusCode }}).', { | ||
statusCode: error.status | ||
}), | ||
this.translateService.instant('Import from the web') | ||
); | ||
this.spinner.hide(); | ||
return NEVER; | ||
} else { | ||
return this.standardHandleError(error); | ||
} | ||
} | ||
} |