1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-13 04:58:19 +00:00

Return 400 but not 500 when request archive with wrong format (#17691) (#17700)

* Return 400 but not 500 when request archive with wrong format (#17691)
* Remove bundle because it's not in this version
This commit is contained in:
Lunny Xiao
2021-11-20 00:31:29 +08:00
committed by GitHub
parent 7be2d7b136
commit a08856606e
4 changed files with 72 additions and 9 deletions

View File

@@ -38,6 +38,22 @@ type ArchiveRequest struct {
// the way to 64.
var shaRegex = regexp.MustCompile(`^[0-9a-f]{4,64}$`)
// ErrUnknownArchiveFormat request archive format is not supported
type ErrUnknownArchiveFormat struct {
RequestFormat string
}
// Error implements error
func (err ErrUnknownArchiveFormat) Error() string {
return fmt.Sprintf("unknown format: %s", err.RequestFormat)
}
// Is implements error
func (ErrUnknownArchiveFormat) Is(err error) bool {
_, ok := err.(ErrUnknownArchiveFormat)
return ok
}
// NewRequest creates an archival request, based on the URI. The
// resulting ArchiveRequest is suitable for being passed to ArchiveRepository()
// if it's determined that the request still needs to be satisfied.
@@ -55,7 +71,7 @@ func NewRequest(repoID int64, repo *git.Repository, uri string) (*ArchiveRequest
ext = ".tar.gz"
r.Type = git.TARGZ
default:
return nil, fmt.Errorf("Unknown format: %s", uri)
return nil, ErrUnknownArchiveFormat{RequestFormat: uri}
}
r.refName = strings.TrimSuffix(uri, ext)