From 3f4022ff231c992550cadfff1a13fd35224d2f17 Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 15 Jan 2025 08:41:16 +0100
Subject: [PATCH] Add more descriptive error message
---
src/app/qualification/delete/delete.component.ts | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/app/qualification/delete/delete.component.ts b/src/app/qualification/delete/delete.component.ts
index e77996b..0d849d0 100644
--- a/src/app/qualification/delete/delete.component.ts
+++ b/src/app/qualification/delete/delete.component.ts
@@ -9,6 +9,7 @@ import {
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import QualificationService from "../../services/qualification.service";
import {MatButton} from "@angular/material/button";
+import {HttpErrorResponse} from "@angular/common/http";
@Component({
selector: 'app-delete-qualification',
@@ -36,10 +37,15 @@ export class DeleteComponent {
next: () => {
this.dialogRef.close(true);
},
- error: (error) => {
+ error: (error: HttpErrorResponse) => {
console.error('Error deleting qualification:', error);
- this.apiError = 'API Error';
+ if (error.error.message.includes('SQL')) {
+ // The API message is undescriptive but this is the most common
+ this.apiError = 'This qualification cannot be modified because it is currently assigned to one or more employees';
+ } else {
+ this.apiError = 'API Error';
+ }
}
});
}
--
2.47.2