mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-04-24 07:10:20 +00:00
First round of patches to re-enable some lints from my side. This PR also refactors the general key fetching code quite a bit due to the way it currently worked with relying on some values being nil sometimes. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11253 Reviewed-by: elle <0xllx0@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: famfo <famfo@famfo.xyz> Co-committed-by: famfo <famfo@famfo.xyz>
52 lines
1 KiB
Go
52 lines
1 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package federation
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type ErrNotAcceptable struct {
|
|
Message string
|
|
}
|
|
|
|
func NewErrNotAcceptablef(format string, a ...any) ErrNotAcceptable {
|
|
message := fmt.Sprintf(format, a...)
|
|
return ErrNotAcceptable{Message: message}
|
|
}
|
|
|
|
func (err ErrNotAcceptable) Error() string {
|
|
return fmt.Sprintf("NotAcceptable: %v", err.Message)
|
|
}
|
|
|
|
type ErrInternal struct {
|
|
Message string
|
|
}
|
|
|
|
func NewErrInternalf(format string, a ...any) ErrInternal {
|
|
message := fmt.Sprintf(format, a...)
|
|
return ErrInternal{Message: message}
|
|
}
|
|
|
|
func (err ErrInternal) Error() string {
|
|
return fmt.Sprintf("InternalServerError: %v", err.Message)
|
|
}
|
|
|
|
func HTTPStatus(err error) int {
|
|
switch err.(type) {
|
|
case ErrNotAcceptable:
|
|
return http.StatusNotAcceptable
|
|
default:
|
|
return http.StatusInternalServerError
|
|
}
|
|
}
|
|
|
|
type ErrKeyNotFound struct {
|
|
KeyID string
|
|
}
|
|
|
|
func (err ErrKeyNotFound) Error() string {
|
|
return fmt.Sprintf("No key found for key ID: %s", err.KeyID)
|
|
}
|