From 065f90f1f759ed4b97dc22a02e331f7a30eb8ee3 Mon Sep 17 00:00:00 2001
From: Gunther6070 <haydenhartman10@yahoo.com>
Date: Mon, 17 Mar 2025 22:17:28 -0400
Subject: Added statusText to components to disable error messages

---
 .../components/cupboard/cupboard.component.html    |  1 +
 .../app/components/cupboard/cupboard.component.ts  | 55 +++++++++++++++++++++-
 2 files changed, 55 insertions(+), 1 deletion(-)

(limited to 'ufund-ui/src')

diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.html b/ufund-ui/src/app/components/cupboard/cupboard.component.html
index 65545e8..59d77e0 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.html
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.html
@@ -19,6 +19,7 @@
         <input type="submit" value="Submit"> 
     </form>
     <button (click)="back()">Close</button>
+    <span *ngIf="statusText">{{statusText | async}}</span>
     
 </div>
 <div id="update-form">
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
index a930f06..4088ae4 100644
--- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts
+++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts
@@ -3,6 +3,7 @@ import { CupboardService } from '../../services/cupboard.service';
 import { UsersService } from '../../services/users.service';
 import { Need, GoalType } from '../../models/Need';
 import { userType } from '../../models/User';
+import { BehaviorSubject, catchError, of } from 'rxjs';
 
 @Component({
   selector: 'app-cupboard',
@@ -12,6 +13,9 @@ import { userType } from '../../models/User';
 })
 
 export class CupboardComponent implements OnInit {
+
+    protected statusText = new BehaviorSubject("")
+
 needs: any;
     constructor(private cupboardService: CupboardService, private usersService: UsersService) { }
 
@@ -121,7 +125,12 @@ needs: any;
       };
       console.log("need:", need);
       console.log("form submitted. creating need: ", need);
-      this.cupboardService.createNeed(need).subscribe(
+      this.cupboardService.createNeed(need)
+      .pipe(catchError((ex, r) => {
+              this.statusText.next("Max goal must be greater than 0 " + friendlyHttpStatus[ex.status])
+              return of()
+          }))
+      .subscribe(
         (result) => {
           if (result) {
             console.log("need created successfully");
@@ -138,3 +147,47 @@ needs: any;
 
     }
   }
+
+let friendlyHttpStatus: {[key: number]: string} = {
+    200: 'OK',
+    201: 'Created',
+    202: 'Accepted',
+    203: 'Non-Authoritative Information',
+    204: 'No Content',
+    205: 'Reset Content',
+    206: 'Partial Content',
+    300: 'Multiple Choices',
+    301: 'Moved Permanently',
+    302: 'Found',
+    303: 'See Other',
+    304: 'Not Modified',
+    305: 'Use Proxy',
+    306: 'Unused',
+    307: 'Temporary Redirect',
+    400: 'Bad Request',
+    401: 'Unauthorized',
+    402: 'Payment Required',
+    403: 'Forbidden',
+    404: 'Not Found',
+    405: 'Method Not Allowed',
+    406: 'Not Acceptable',
+    407: 'Proxy Authentication Required',
+    408: 'Request Timeout',
+    409: 'Conflict',
+    410: 'Gone',
+    411: 'Length Required',
+    412: 'Precondition Required',
+    413: 'Request Entry Too Large',
+    414: 'Request-URI Too Long',
+    415: 'Unsupported Media Type',
+    416: 'Requested Range Not Satisfiable',
+    417: 'Expectation Failed',
+    418: 'I\'m a teapot',
+    429: 'Too Many Requests',
+    500: 'Internal Server Error',
+    501: 'Not Implemented',
+    502: 'Bad Gateway',
+    503: 'Service Unavailable',
+    504: 'Gateway Timeout',
+    505: 'HTTP Version Not Supported',
+};
\ No newline at end of file
-- 
cgit v1.2.3