From 1062f218f10aa80d35df40b3fc8b91334163780b Mon Sep 17 00:00:00 2001 From: rslangl Date: Wed, 29 Apr 2026 21:14:50 +0200 Subject: [PATCH 1/2] chore: remove superfluous custom error type --- internal/api/impl.go | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/internal/api/impl.go b/internal/api/impl.go index e07a04a..03dd8e5 100644 --- a/internal/api/impl.go +++ b/internal/api/impl.go @@ -11,23 +11,6 @@ import ( "artifacts/internal/storage/storage_error" ) -type ArtifactErrorMessage interface { - ResourceNotFound(resource string, version string) - InternalServerError(resource string, version string) -} - -type ArtifactError struct { - ErrorMessage string -} - -func (e* ArtifactError) ResourceNotFound(resource string, version string) { - e.ErrorMessage = fmt.Sprintf("The requested resource '%v:%v' was not found", resource, version) -} - -func (e* ArtifactError) InternalServerError(resource string, version string) { - e.ErrorMessage = fmt.Sprintf("Internal server error occurred while fetching the requested resource '%v:%v'", resource, version) -} - type Server struct{ storageHandler storage.Storage } @@ -49,24 +32,30 @@ func (s Server) GetCharts(w http.ResponseWriter, r *http.Request) { } func (s Server) GetChart(w http.ResponseWriter, r *http.Request, resource string, version string) { + w.Header().Set("Content-Type", "application/json") + data, err := s.storageHandler.Read(resource, version) + if err != nil { - e := &ArtifactError{} if err == storage_error.NotFound { - e.ResourceNotFound(resource, version) w.WriteHeader(http.StatusNotFound) - w.Header().Set("Content-Type", "application/json") - _ = json.NewEncoder(w).Encode(e) + _ = json.NewEncoder(w).Encode(Error{ + Code: new(int(http.StatusNotFound)), + Message: new(string(fmt.Sprintf("Resource '%v:%v' was not found", resource, version)), + }) return } + e.InternalServerError(resource, version) w.WriteHeader(http.StatusInternalServerError) - w.Header().Set("Content-Type", "application/json") - _ = json.NewEncoder(w).Encode(e) + _ = json.NewEncoder(w).Encode(Error{ + Code: new(int(http.StatusInternalServerError), + Message: new(string(fmt.Sprintf("Internal server error occurred for '%v:%v'", resource, version))), + }) return } + w.WriteHeader(http.StatusOK) - w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(data) } From 356f33a282d85a025d1e6501c7bbc7bd8f079a41 Mon Sep 17 00:00:00 2001 From: rslangl Date: Wed, 29 Apr 2026 21:17:20 +0200 Subject: [PATCH 2/2] chore: minor fixes --- internal/api/impl.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/api/impl.go b/internal/api/impl.go index 03dd8e5..8c9f471 100644 --- a/internal/api/impl.go +++ b/internal/api/impl.go @@ -41,15 +41,14 @@ func (s Server) GetChart(w http.ResponseWriter, r *http.Request, resource string w.WriteHeader(http.StatusNotFound) _ = json.NewEncoder(w).Encode(Error{ Code: new(int(http.StatusNotFound)), - Message: new(string(fmt.Sprintf("Resource '%v:%v' was not found", resource, version)), + Message: new(string(fmt.Sprintf("Resource '%v:%v' was not found", resource, version))), }) return } - e.InternalServerError(resource, version) w.WriteHeader(http.StatusInternalServerError) _ = json.NewEncoder(w).Encode(Error{ - Code: new(int(http.StatusInternalServerError), + Code: new(int(http.StatusInternalServerError)), Message: new(string(fmt.Sprintf("Internal server error occurred for '%v:%v'", resource, version))), }) return