From 3a58ebc6d4df0bb524117c847606a999baff9cf7 Mon Sep 17 00:00:00 2001
From: Tobias Pfandzelter <pfandzelter@campus.tu-berlin.de>
Date: Fri, 17 Jan 2020 11:04:37 +0100
Subject: [PATCH] replace fmt.Errorf with new custom error type

---
 pkg/errors/errors.go         | 4 ++--
 pkg/exthandler/exthandler.go | 2 +-
 pkg/inthandler/inthandler.go | 6 +++---
 pkg/replication/address.go   | 4 +++-
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go
index 8528a7c2..f3866c1f 100644
--- a/pkg/errors/errors.go
+++ b/pkg/errors/errors.go
@@ -16,6 +16,7 @@ const (
 	StatusConflict int = http.StatusConflict
 	StatusBadRequest int = http.StatusBadRequest
 	StatusNotFound int = http.StatusNotFound
+	StatusInternalError int = http.StatusInternalServerError
 )
 
 // Error is needed to satisfy the interface of error for Error.
@@ -29,5 +30,4 @@ func New(code int, error string) *Error {
 		Code:  code,
 		error: error,
 	}
-}
-
+}
\ No newline at end of file
diff --git a/pkg/exthandler/exthandler.go b/pkg/exthandler/exthandler.go
index de41b38c..eb95dd4a 100644
--- a/pkg/exthandler/exthandler.go
+++ b/pkg/exthandler/exthandler.go
@@ -185,7 +185,7 @@ func (h *handler) HandleAddNode(n []replication.Node) error {
 	}
 
 	if ec > 0 {
-		return fmt.Errorf("exthandler: %v", e)
+		return errors.New(errors.StatusInternalError, fmt.Sprintf("exthandler: %v", e))
 	}
 
 	return nil
diff --git a/pkg/inthandler/inthandler.go b/pkg/inthandler/inthandler.go
index 2a18f00f..1a130dee 100644
--- a/pkg/inthandler/inthandler.go
+++ b/pkg/inthandler/inthandler.go
@@ -65,7 +65,7 @@ func (h *handler) HandleCreateKeygroup(k keygroup.Keygroup, nodes []replication.
 	}
 
 	if ec > 0 {
-		return fmt.Errorf("exthandler: %v", e)
+		return errors.New(errors.StatusInternalError, fmt.Sprintf("exthandler: %v", e))
 	}
 
 	return nil
@@ -154,7 +154,7 @@ func (h *handler) HandleIntroduction(self replication.Node, node []replication.N
 	}
 
 	if ec > 0 {
-		return fmt.Errorf("exthandler: %v", e)
+		return errors.New(errors.StatusInternalError, fmt.Sprintf("exthandler: %v", e))
 	}
 
 	return nil
@@ -185,7 +185,7 @@ func (h *handler) HandleDetroduction() error {
 	}
 
 	if ec > 0 {
-		return fmt.Errorf("exthandler: %v", e)
+		return errors.New(errors.StatusInternalError, fmt.Sprintf("exthandler: %v", e))
 	}
 
 	return nil
diff --git a/pkg/replication/address.go b/pkg/replication/address.go
index 35fb0acc..a4862535 100644
--- a/pkg/replication/address.go
+++ b/pkg/replication/address.go
@@ -6,6 +6,8 @@ import (
 	"regexp"
 
 	"github.com/rs/zerolog/log"
+
+	"gitlab.tu-berlin.de/mcc-fred/fred/pkg/errors"
 )
 
 // Address is an IP address or a hostname of a FReD node.
@@ -44,7 +46,7 @@ func ParseAddress(a string) (Address, error) {
 	}
 
 	if !matched {
-		return Address{}, fmt.Errorf("replication.address: could not validate %s as IP address or hostname", a)
+		return Address{}, errors.New(errors.StatusBadRequest, fmt.Sprintf("replication.address: could not validate %s as IP address or hostname", a))
 	}
 
 	return Address{
-- 
GitLab