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=
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"
)
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
}
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"
)
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
}
--- /dev/null
+/*
+==================================================================================
+
+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
+}