mirror of
https://github.com/harness/drone.git
synced 2025-05-04 07:29:21 +08:00

* update migrator mdoule * added formatted forbidden error helper * delete work sum * check branch rule identifier check * match migrator data contract for webhooks * self review * self review * self review, code cleaning * resolve conflicts * updated import api calls * resolve conflicts * lint * bypass pre-receive block ref update on push if it's migrator push * migrate controller and apis * pull main * add migrate routes to terminate path prefix apis * move apis to migrate pkg * Merge branch 'main' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into atmsn/import_meta * import branch rules API * wip import webhooks
72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
// Copyright 2023 Harness, Inc.
|
|
//
|
|
// 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 render
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/harness/gitness/app/api/usererror"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// TranslatedUserError writes the translated user error of the provided error.
|
|
func TranslatedUserError(ctx context.Context, w http.ResponseWriter, err error) {
|
|
UserError(ctx, w, usererror.Translate(ctx, err))
|
|
}
|
|
|
|
// NotFound writes the json-encoded message for a not found error.
|
|
func NotFound(ctx context.Context, w http.ResponseWriter) {
|
|
UserError(ctx, w, usererror.ErrNotFound)
|
|
}
|
|
|
|
// Unauthorized writes the json-encoded message for an unauthorized error.
|
|
func Unauthorized(ctx context.Context, w http.ResponseWriter) {
|
|
UserError(ctx, w, usererror.ErrUnauthorized)
|
|
}
|
|
|
|
// Forbidden writes the json-encoded message for a forbidden error.
|
|
func Forbidden(ctx context.Context, w http.ResponseWriter) {
|
|
UserError(ctx, w, usererror.ErrForbidden)
|
|
}
|
|
|
|
// Forbiddenf writes the json-encoded message with a forbidden error.
|
|
func Forbiddenf(ctx context.Context, w http.ResponseWriter, format string, args ...interface{}) {
|
|
UserError(ctx, w, usererror.Newf(http.StatusForbidden, format, args...))
|
|
}
|
|
|
|
// BadRequest writes the json-encoded message for a bad request error.
|
|
func BadRequest(ctx context.Context, w http.ResponseWriter) {
|
|
UserError(ctx, w, usererror.ErrBadRequest)
|
|
}
|
|
|
|
// BadRequestf writes the json-encoded message with a bad request status code.
|
|
func BadRequestf(ctx context.Context, w http.ResponseWriter, format string, args ...interface{}) {
|
|
UserError(ctx, w, usererror.Newf(http.StatusBadRequest, format, args...))
|
|
}
|
|
|
|
// InternalError writes the json-encoded message for an internal error.
|
|
func InternalError(ctx context.Context, w http.ResponseWriter) {
|
|
UserError(ctx, w, usererror.ErrInternal)
|
|
}
|
|
|
|
// UserError writes the json-encoded user error.
|
|
func UserError(ctx context.Context, w http.ResponseWriter, err *usererror.Error) {
|
|
log.Ctx(ctx).Debug().Err(err).Msgf("operation resulted in user facing error")
|
|
|
|
JSON(w, err.Status, err)
|
|
}
|