Compare commits

..

1 Commits

Author SHA1 Message Date
DaneEveritt
ac81409505 clearer error messaging on downloads, don't log as a 500-level error 2026-04-01 17:25:18 -07:00
3 changed files with 32 additions and 9 deletions

View File

@@ -53,7 +53,7 @@ jobs:
echo "short_sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Build and Push (tag)
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
if: "github.event_name == 'release' && github.event.action == 'published'"
with:
context: .
@@ -66,7 +66,7 @@ jobs:
tags: ${{ steps.docker_meta.outputs.tags }}
- name: Build and Push (develop)
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
if: "github.event_name == 'push' && contains(github.ref, 'develop')"
with:
context: .

View File

@@ -25,6 +25,7 @@ var client *http.Client
func init() {
dialer := &net.Dialer{
LocalAddr: nil,
Timeout: time.Second * 30,
}
trnspt := http.DefaultTransport.(*http.Transport).Clone()
@@ -55,10 +56,8 @@ func init() {
}
client = &http.Client{
Timeout: time.Hour * 12,
Timeout: time.Hour * 2,
Transport: trnspt,
// Disallow any redirect on an HTTP call. This is a security requirement: do not modify
// this logic without first ensuring that the new target location IS NOT within the current
// instance's local network.
@@ -192,7 +191,10 @@ func (dl *Download) Execute() error {
req.Header.Set("User-Agent", "Pterodactyl Panel (https://pterodactyl.io)")
res, err := client.Do(req)
if err != nil {
return ErrDownloadFailed
if IsDownloadError(err) {
return err
}
return errors.Wrap(err, ErrDownloadFailed.Error())
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
@@ -335,3 +337,7 @@ func mustParseCIDR(ip string) *net.IPNet {
}
return block
}
func IsDownloadError(err error) bool {
return errors.Is(err, ErrDownloadFailed) || errors.Is(err, ErrInvalidIPAddress) || errors.Is(err, ErrInternalResolution)
}

View File

@@ -328,13 +328,15 @@ func postServerPullRemoteFile(c *gin.Context) {
download := func() error {
s.Log().WithField("download_id", dl.Identifier).WithField("url", u.String()).Info("starting pull of remote file to disk")
if err := dl.Execute(); err != nil {
s.Log().WithField("download_id", dl.Identifier).WithField("error", err).Error("failed to pull remote file")
if !downloader.IsDownloadError(err) {
s.Log().WithField("download_id", dl.Identifier).WithField("error", err).Error("failed to pull remote file")
}
return err
} else {
s.Log().WithField("download_id", dl.Identifier).Info("completed pull of remote file")
}
s.Log().WithField("download_id", dl.Identifier).Info("completed pull of remote file")
return nil
}
if !data.Foreground {
go func() {
_ = download()
@@ -346,6 +348,21 @@ func postServerPullRemoteFile(c *gin.Context) {
}
if err := download(); err != nil {
if downloader.IsDownloadError(err) {
var message = "The URL or IP address provided could not be resolved to a valid destination."
if errors.Is(err, downloader.ErrDownloadFailed) {
s.Log().WithField("identifier", dl.Identifier).WithField("error", err).Warn("failed to download remote file")
message = "An error was encountered while trying to download this file. Please try again later."
}
c.JSON(http.StatusBadRequest, gin.H{
"identifier": dl.Identifier,
"message": message,
})
return
}
middleware.CaptureAndAbort(c, err)
return
}