1 Star 0 Fork 0

pengchengduan / goharbor-client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
project_errors.go 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
pengchengduan 提交于 2024-02-01 17:28 . first commit
package project
import (
"net/http"
"github.com/go-openapi/runtime"
projectapi "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/project"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/errors"
)
// handleSwaggerProjectErrors takes a swagger generated error as input,
// which usually does not contain any form of error message,
// and outputs a new error with a proper message.
func handleSwaggerProjectErrors(in error) error {
t, ok := in.(*runtime.APIError)
if ok {
switch t.Code {
case http.StatusCreated:
// Harbor sometimes returns 201 instead of 200 despite the swagger spec
// not declaring it.
return nil
case http.StatusBadRequest:
return &errors.ErrProjectIllegalIDFormat{}
case http.StatusUnauthorized:
return &errors.ErrUnauthorized{}
case http.StatusForbidden:
return &errors.ErrProjectNoPermission{}
case http.StatusNotFound:
return &errors.ErrProjectUnknownResource{}
case http.StatusInternalServerError:
return &errors.ErrProjectInternalErrors{}
}
}
switch in.(type) {
case *projectapi.DeleteProjectNotFound:
return &errors.ErrProjectIDNotExists{}
case *projectapi.UpdateProjectNotFound:
return &errors.ErrProjectIDNotExists{}
case *projectapi.CreateProjectConflict:
return &errors.ErrProjectNameAlreadyExists{}
default:
return in
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pengchengduan/goharbor-client.git
git@gitee.com:pengchengduan/goharbor-client.git
pengchengduan
goharbor-client
goharbor-client
41c6882efe91

搜索帮助

344bd9b3 5694891 D2dac590 5694891