From e2586de8e25da24b57933948fffd620219d23a18 Mon Sep 17 00:00:00 2001
From: Torgrim <sir_alexiner@hotmail.com>
Date: Thu, 11 Apr 2024 01:35:32 +0200
Subject: [PATCH] Updated Error Handling to be more Precise

---
 Go/internal/func/dashboardFunctions.go             |  3 ++-
 Go/internal/func/supported_countries.go            | 14 ++++----------
 .../handlers/endpoint/dashboard/status_handler.go  |  4 ++--
 3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/Go/internal/func/dashboardFunctions.go b/Go/internal/func/dashboardFunctions.go
index e4d3de1..adf28b0 100644
--- a/Go/internal/func/dashboardFunctions.go
+++ b/Go/internal/func/dashboardFunctions.go
@@ -2,6 +2,7 @@ package _func
 
 import (
 	"encoding/json"
+	"errors"
 	"fmt"
 	"globeboard/internal/utils/constants/External"
 	"globeboard/internal/utils/structs"
@@ -283,5 +284,5 @@ func getExchangeRateList(isocode string) (map[string]float64, error) {
 		return rates, nil
 	}
 
-	return nil, fmt.Errorf("no currency currency found")
+	return nil, errors.New("no currency currency found")
 }
diff --git a/Go/internal/func/supported_countries.go b/Go/internal/func/supported_countries.go
index 010474b..bad5fc4 100644
--- a/Go/internal/func/supported_countries.go
+++ b/Go/internal/func/supported_countries.go
@@ -13,13 +13,7 @@ import (
 	"time"
 )
 
-// CountryInfo represents the necessary information about a country, focusing on its common name and cca2 code.
-type CountryInfo struct {
-	CommonName string `json:"commonName"`
-	ISOCode    string `json:"isoCode"`
-}
-
-// GetSupportedCountries fetches countries with their common names and cca2 codes.
+// getSupportedCountries fetches countries with their common names and cca2 codes.
 func getSupportedCountries() (map[string]string, error) {
 	url := fmt.Sprintf("%sall?fields=name,cca2", External.CountriesAPI)
 	var responseData []struct {
@@ -32,18 +26,18 @@ func getSupportedCountries() (map[string]string, error) {
 	client := &http.Client{Timeout: 10 * time.Second}
 	req, err := http.NewRequest(http.MethodGet, url, nil)
 	if err != nil {
-		return nil, fmt.Errorf("error creating request: %s", err)
+		return nil, fmt.Errorf("error creating request: %v", err)
 	}
 	req.Header.Add("content-type", "application/json")
 
 	res, err := client.Do(req)
 	if err != nil {
-		return nil, fmt.Errorf("error issuing request: %s", err)
+		return nil, fmt.Errorf("error issuing request: %v", err)
 	}
 
 	err = json.NewDecoder(res.Body).Decode(&responseData)
 	if err != nil {
-		return nil, fmt.Errorf("error decoding JSON: %s", err)
+		return nil, fmt.Errorf("error decoding JSON: %v", err)
 	}
 
 	countriesMap := make(map[string]string)
diff --git a/Go/internal/handlers/endpoint/dashboard/status_handler.go b/Go/internal/handlers/endpoint/dashboard/status_handler.go
index ae9f9b1..fbfdc2a 100644
--- a/Go/internal/handlers/endpoint/dashboard/status_handler.go
+++ b/Go/internal/handlers/endpoint/dashboard/status_handler.go
@@ -19,7 +19,7 @@ func getEndpointStatus(endpointURL string) string {
 	r, err := http.NewRequest(http.MethodGet, endpointURL, nil)
 	if err != nil {
 		// Log and handle the error if request creation fails.
-		err := fmt.Errorf("error in creating request: %s", err.Error())
+		err := fmt.Errorf("error in creating request: %v", err)
 		log.Println(err)
 	}
 
@@ -34,7 +34,7 @@ func getEndpointStatus(endpointURL string) string {
 	res, err := client.Do(r)
 	if err != nil {
 		// Log and handle the error if request execution fails.
-		err := fmt.Errorf("error in response: %s", err.Error())
+		err := fmt.Errorf("error in response: %v", err)
 		log.Println(err)
 	}
 
-- 
GitLab