Define errors 70/11070/1
authorYouhwan Seol <yh.seol@samsung.com>
Tue, 21 Feb 2023 04:06:41 +0000 (13:06 +0900)
committerYouhwan Seol <yh.seol@samsung.com>
Wed, 10 May 2023 10:51:17 +0000 (19:51 +0900)
Change-Id: I846aebe7bdf2e2042e3938e9df3d1db400dc3c55
Signed-off-by: Youhwan Seol <yh.seol@samsung.com>
go.sum
pkg/api/v1/deployment/deployment.go
pkg/client/onboard/utils.go
pkg/commons/errors/errors.go [new file with mode: 0644]

diff --git a/go.sum b/go.sum
index 726edeb..7aee98d 100755 (executable)
--- a/go.sum
+++ b/go.sum
@@ -41,8 +41,6 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
 github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
 github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
 github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
-github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
-github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
index 44a6001..fbc4fd0 100644 (file)
@@ -20,12 +20,12 @@ limitations under the License.
 package deployment
 
 import (
-       "errors"
        "net/http"
 
        "github.com/gin-gonic/gin"
 
        "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/utils"
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/errors"
        "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
 )
 
@@ -43,13 +43,13 @@ func (Executor) Deploy(c *gin.Context) {
 
        name := c.Query("name")
        if name == "" {
-               utils.WriteError(c.Writer, errors.New("empty query"))
+               utils.WriteError(c.Writer, errors.InvalidIPSName{Message: "Empty Query"})
                return
        }
 
        version := c.Query("version")
        if version == "" {
-               utils.WriteError(c.Writer, errors.New("empty query"))
+               utils.WriteError(c.Writer, errors.InvalidIPSName{Message: "Empty Query"})
                return
        }
 
index a555345..2a04e2e 100644 (file)
@@ -28,12 +28,13 @@ import (
        netUrl "net/url"
        "os"
        "path/filepath"
+       "strconv"
        "strings"
        "time"
 
        "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/url"
-       "github.com/pkg/errors"
 
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/errors"
        "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
 )
 
@@ -99,13 +100,13 @@ func requestToOnboard(url string) (*http.Response, error) {
        resp, err := http.Get(url)
        if err != nil {
                logger.Logging(logger.ERROR, err.Error())
-               // TODO : define errors
-               return nil, errors.Wrap(err, "internal server error")
+               return nil, errors.InternalServerError{Message: err.Error()}
        }
 
        if resp.StatusCode != http.StatusOK {
-               // TODO : define errors
-               err = errors.New("internal server error")
+               err = errors.InternalServerError{
+                       Message: "onboard return error, status code : " + strconv.Itoa(int(resp.StatusCode)),
+               }
                logger.Logging(logger.ERROR, err.Error())
                return nil, err
        }
diff --git a/pkg/commons/errors/errors.go b/pkg/commons/errors/errors.go
new file mode 100644 (file)
index 0000000..6fe9ba2
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+==================================================================================
+
+Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==================================================================================
+*/
+
+package errors
+
+type Unknown struct {
+       Message string `json:"message" example:"unknown error: {reason}" format:"string"`
+}
+
+func (e Unknown) Error() string {
+       return "unknown error: " + e.Message
+}
+
+type NotFoundURL struct {
+       Message string `json:"message" example:"unsupported url: {reason}" format:"string"`
+}
+
+func (e NotFoundURL) Error() string {
+       return "unsupported url: " + e.Message
+}
+
+type InvalidMethod struct {
+       Message string `json:"message" example:"invalid method: {reason}" format:"string"`
+}
+
+func (e InvalidMethod) Error() string {
+       return "invalid method: " + e.Message
+}
+
+type InvalidIPSName struct {
+       Message string `json:"message" example:"invalid ips name: {reason}" format:"string"`
+}
+
+func (e InvalidIPSName) Error() string {
+       return "invalid IPS name: " + e.Message
+}
+
+type NotFoundIPS struct {
+       Message string `json:"message" example:"not found ips: {reason}" format:"string"`
+}
+
+func (e NotFoundIPS) Error() string {
+       return "not found ips: " + e.Message
+}
+
+type IOError struct {
+       Message string `json:"message" example:"io error: {reason}" format:"string"`
+}
+
+func (e IOError) Error() string {
+       return "io error: " + e.Message
+}
+
+type TimeoutError struct {
+       Message string `json:"message" example:"time out error: {reason}" format:"string"`
+}
+
+func (e TimeoutError) Error() string {
+       return "time out error: " + e.Message
+}
+
+type InternalServerError struct {
+       Message string `json:"message" example:"internal server error: {reason}" format:"string"`
+}
+
+func (e InternalServerError) Error() string {
+       return "internal server error: " + e.Message
+}