Skip to content

Commit b9f24f9

Browse files
committed
miniogw: correctly map uplink limit errors to S3 responses
currently we are responding with a somewhat misleading error when the bandwidth limit has exceeded, reporting that the upload limit has been exceeded when in actual fact it was the bandwidth. Change-Id: I0d4add6e9e68a8a98398f54397bc0ddb9daf38c0
1 parent 219a346 commit b9f24f9

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

miniogw/gateway.go

+31-6
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,39 @@ import (
3232
var (
3333
mon = monkit.Package()
3434

35-
// ErrProjectUsageLimit is a custom error for when a user has reached their
36-
// Satellite project upload limit.
35+
// ErrBandwidthLimitExceeded is a custom error for when a user has reached their
36+
// Satellite bandwidth limit.
37+
//
38+
// Note: we went with 403 Forbidden over 509 Bandwidth Limit Exceeded, as 509
39+
// is not an official status code and rarely used outside of Apache/cPanel.
40+
// In this case though the user can solve it themselves by getting a
41+
// limit increase, so it should be treated as a 4xx level error, not 5xx.
42+
ErrBandwidthLimitExceeded = miniogo.ErrorResponse{
43+
Code: "XStorjBandwidthLimitExceeded",
44+
StatusCode: http.StatusForbidden,
45+
Message: "You have reached your Storj project bandwidth limit on the Satellite.",
46+
}
47+
48+
// ErrStorageLimitExceeded is a custom error for when a user has reached their
49+
// Satellite storage limit.
3750
//
3851
// Note: we went with 403 Forbidden over 507 Insufficient Storage, as 507
3952
// doesn't fit this case exactly. 507 is for when the server cannot
4053
// physically store any further data, e.g. the disk has filled up. In this
4154
// case though the user can solve this themselves by upgrading their plan,
4255
// so it should be treated as a 4xx level error, not 5xx.
43-
ErrProjectUsageLimit = miniogo.ErrorResponse{
44-
Code: "XStorjProjectLimits",
56+
ErrStorageLimitExceeded = miniogo.ErrorResponse{
57+
Code: "XStorjStorageLimitExceeded",
58+
StatusCode: http.StatusForbidden,
59+
Message: "You have reached your Storj project storage limit on the Satellite.",
60+
}
61+
62+
// ErrSegmentsLimitExceeded is a custom error for when a user has reached their
63+
// Satellite segment limit.
64+
ErrSegmentsLimitExceeded = miniogo.ErrorResponse{
65+
Code: "XStorjSegmentsLimitExceeded",
4566
StatusCode: http.StatusForbidden,
46-
Message: "You have reached your Storj project upload limit on the Satellite.",
67+
Message: "You have reached your Storj project segment limit on the Satellite.",
4768
}
4869

4970
// ErrSlowDown is a custom error for when a user is exceeding Satellite
@@ -1096,7 +1117,11 @@ func convertError(err error, bucket, object string) error {
10961117
case errors.Is(err, uplink.ErrObjectNotFound):
10971118
return minio.ObjectNotFound{Bucket: bucket, Object: object}
10981119
case errors.Is(err, uplink.ErrBandwidthLimitExceeded):
1099-
return ErrProjectUsageLimit
1120+
return ErrBandwidthLimitExceeded
1121+
case errors.Is(err, uplink.ErrStorageLimitExceeded):
1122+
return ErrStorageLimitExceeded
1123+
case errors.Is(err, uplink.ErrSegmentsLimitExceeded):
1124+
return ErrSegmentsLimitExceeded
11001125
case errors.Is(err, uplink.ErrPermissionDenied):
11011126
return minio.PrefixAccessDenied{Bucket: bucket, Object: object}
11021127
case errors.Is(err, uplink.ErrTooManyRequests):

testsuite/miniogw/gateway_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,7 @@ func TestProjectUsageLimit(t *testing.T) {
35613561
// An extra download should return 'Exceeded Usage Limit' error
35623562
err = minio.GetObject(ctxWithProject, layer, "testbucket", "test/path1", 0, -1, ioutil.Discard, "", minio.ObjectOptions{})
35633563
require.Error(t, err)
3564-
require.ErrorIs(t, err, miniogw.ErrProjectUsageLimit)
3564+
require.ErrorIs(t, err, miniogw.ErrBandwidthLimitExceeded)
35653565

35663566
// Simulate new billing cycle (next month)
35673567
planet.Satellites[0].API.Accounting.ProjectUsage.SetNow(func() time.Time {

0 commit comments

Comments
 (0)