mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-11 05:36:44 +02:00
Fix parts of issue #8221 and part of PR #4767
Is linked to https://codeberg.org/forgejo/forgejo/pulls/8274
The commit 555f6e57ad
fixes timeout forgejo/forgejo#8274 (Kommentar)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8708
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de>
Co-committed-by: Michael Jerger <michael.jerger@meissa-gmbh.de>
44 lines
904 B
Go
44 lines
904 B
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
|
|
}
|
|
}
|