Skip to content

Commit

Permalink
chore: errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jahzielv committed Sep 16, 2024
1 parent ba65071 commit 0d8571b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/mdm/maintainedapps/installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func DownloadInstaller(ctx context.Context, installerURL string, maxSize int64)
_, err := url.ParseRequestURI(installerURL)
if err != nil {
return nil, "", fleet.NewInvalidArgumentError(
"software.url",
"fleet_maintained_app.url",
fmt.Sprintf("Couldn't download maintained app installer. URL (%q) is invalid", installerURL),
)
}
Expand All @@ -40,7 +40,7 @@ func DownloadInstaller(ctx context.Context, installerURL string, maxSize int64)
var maxBytesErr *http.MaxBytesError
if errors.Is(err, fleethttp.ErrMaxSizeExceeded) || errors.As(err, &maxBytesErr) {
return nil, "", fleet.NewInvalidArgumentError(
"software.url",
"fleet_maintained_app.url",
fmt.Sprintf("Couldn't download maintained app installer. URL (%q). The maximum file size is %d MB", installerURL, maxSize/(1024*1024)),
)
}
Expand All @@ -51,15 +51,15 @@ func DownloadInstaller(ctx context.Context, installerURL string, maxSize int64)

if resp.StatusCode == http.StatusNotFound {
return nil, "", fleet.NewInvalidArgumentError(
"software.url",
"fleet_maintained_app.url",
fmt.Sprintf("Couldn't download maintained app installer. URL (%q) doesn't exist. Please make sure that URLs are publicy accessible to the internet.", installerURL),
)
}

// Allow all 2xx and 3xx status codes in this pass.
if resp.StatusCode > 400 {
return nil, "", fleet.NewInvalidArgumentError(
"software.url",
"fleet_maintained_app.url",
fmt.Sprintf("Couldn't download maintained app installer. URL (%q) received response status code %d.", installerURL, resp.StatusCode),
)
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func DownloadInstaller(ctx context.Context, installerURL string, maxSize int64)
var maxBytesErr *http.MaxBytesError
if errors.Is(err, fleethttp.ErrMaxSizeExceeded) || errors.As(err, &maxBytesErr) {
return nil, "", fleet.NewInvalidArgumentError(
"software.url",
"fleet_maintained_app.url",
fmt.Sprintf("Couldn't download maintained app installer. URL (%q). The maximum file size is %d MB", installerURL, maxSize/(1024*1024)),
)
}
Expand Down

0 comments on commit 0d8571b

Please sign in to comment.