mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-22 02:11:12 +00:00
fix: assorted ActivityPub code only refactors (#8708)
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>
This commit is contained in:
parent
106707b40f
commit
388e4eb44b
20 changed files with 744 additions and 69 deletions
44
services/federation/error.go
Normal file
44
services/federation/error.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
// 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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue