# Error codes and troubleshooting

> The S4 error response format, a reference table of common error codes, and how to troubleshoot SignatureDoesNotMatch, AccessDenied, SlowDown, and other issues.

When a request fails, S4 returns an HTTP status code and an XML error message. Look up the meaning and the fix by `Code` in the tables below.

## Error response

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>AccessDenied</Code>
  <Message>Access Denied.</Message>
  <RequestId>1795515998868996309</RequestId>
  <Key>x.txt</Key>
  <HostID>Ed6IhpST4VqRFmgv3eFI...</HostID>
</Error>
```

| Field       | Description                                                                 |
| ----------- | --------------------------------------------------------------------------- |
| `Code`      | The error code. Programs should decide based on it and the HTTP status code |
| `Message`   | An English description that may change; do not use it for decisions         |
| `RequestId` | The request ID, identical to the `x-amz-request-id` response header         |
| `Key`       | The requested object key                                                    |
| `HostID`    | Used by support to locate the request; include it when you contact us       |

- Every response (including successful ones) carries `x-amz-request-id`. When you contact support, provide it along with the request time and the full error message.
- HEAD requests have no response body, so only the status code is available.
- The 304 and 412 responses to conditional reads have no response body.
- When accessed as a website through a bound domain or a CDN, 403 and 404 return an HTML page instead of XML.

## Authentication and signatures

| Status | Code                                                                            | Meaning                                                                                        | What to do                                                                                                |
| ------ | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| 403    | `InvalidAccessKeyId`                                                            | The AccessKey does not exist                                                                   | Check for typos, check whether it was deleted, and check that the endpoint is `https://s3.bitiful.net`    |
| 403    | `SignatureDoesNotMatch`                                                         | The signature does not match                                                                   | See the [checklist](https://docs.bitiful.com/bitiful-s4/intro.md#signaturedoesnotmatch-checklist)         |
| 403    | `RequestTimeTooSkewed`                                                          | The request time is more than 15 minutes earlier than the server time                          | Correct the local clock                                                                                   |
| 403    | `AccessDenied`（Request is not valid yet）                                        | The request time is more than 15 minutes later than the server time                            | Correct the local clock                                                                                   |
| 403    | `AccessDenied`（Request has expired）                                             | The presigned link has expired                                                                 | Generate a new one                                                                                        |
| 403    | `AccessDenied`（There were headers present in the request which were not signed） | The request carries an unsigned `x-amz-*` header                                               | Add the header to the signature, or remove it                                                             |
| 400    | `AuthorizationQueryParametersError`                                             | A presigned parameter is missing or malformed, or the validity period exceeds 604800 seconds   | Fix the parameters as described                                                                           |
| 400    | `MissingFields`、`InvalidArgument`                                               | The `Authorization` header is malformed                                                        | Sign with an SDK, or check the format of your hand-written signature                                      |
| 400    | `InvalidRequest`                                                                | The signing method is not supported, or the service name in the credential scope is not `s3`   | Use V4 signing                                                                                            |
| 400    | `XAmzContentSHA256Mismatch`                                                     | The SHA-256 of the content does not match `x-amz-content-sha256`, or its value is inconsistent | Sign with an SDK, or check the digest in a hand-written signature; don't change the content after signing |

## Permissions and access restrictions

| Status | Code                    | Meaning                                                                              | What to do                                                                                                                                                                                                                                 |
| ------ | ----------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 403    | `AccessDenied`          | No permission, or denied by an access control list                                   | See the [checklist](https://docs.bitiful.com/bitiful-s4/intro.md#accessdenied-checklist)                                                                                                                                                   |
| 403    | `BucketHasBeenBanned`   | The bucket is suspended. The cause may be an overdue balance or a ban for violations | First check your account balance. If the balance is overdue, [top up](https://docs.bitiful.com/en/prices/handbook/recharge.md); service resumes automatically once the balance is positive. If the balance is not overdue, contact support |
| 403    | `OriginalFileProtected` | Original file protection is on, so anonymous access to the original file is denied   | Access through a Style, or use a presigned link. See [Original file protection](https://docs.bitiful.com/en/coreix/handbook/origin-protect.md)                                                                                             |
| 403    | `FileTypeForbidden`     | `.apk` and `.ipa` files cannot be downloaded directly from S4                        | Use a [CDN](https://docs.bitiful.com/en/cdn/intro.md)                                                                                                                                                                                      |
| 403    | `ReachTheMaxRequests`   | The presigned link exceeded its `x-bitiful-max-requests` count                       | Generate a new link. See [Presigned URLs](https://docs.bitiful.com/en/developer/s3/presigned-url.md)                                                                                                                                       |

## Buckets

| Status | Code                                                                       | Meaning                                         | What to do                                                                             |
| ------ | -------------------------------------------------------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------- |
| 404    | `NoSuchBucket`                                                             | The bucket does not exist                       | Check the bucket name. Without permission, a nonexistent bucket also returns 403       |
| 409    | `BucketAlreadyExists`                                                      | The bucket name is already used by someone else | Pick another name; bucket names are globally unique                                    |
| 409    | `BucketAlreadyOwnedByYou`                                                  | The bucket already belongs to you               | You can use it directly                                                                |
| 409    | `BadBucketName`、`BucketNameTooShort`、`BucketNameTooLong`                   | The bucket name is invalid                      | See the [naming rules](https://docs.bitiful.com/en/bitiful-s4/definitions.md)          |
| 400    | `TooManyBuckets`                                                           | The number of buckets exceeds the quota         | See [Limits](https://docs.bitiful.com/en/bitiful-s4/limits.md)                         |
| 409    | `BucketNotEmpty`                                                           | The bucket is not empty                         | Empty it before deleting                                                               |
| 400    | `CORSTooManyRules`、`CORSRuleTooManyDomains`、`CORSNoRule`、`CORSDuplicateID` | The CORS rules are invalid                      | Up to 10 rules, each with up to 10 origins; at least one rule; rule IDs must be unique |

## Objects and uploads

| Status | Code                                              | Meaning                                                                                                                                                                               | What to do                                                                                                    |
| ------ | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| 404    | `NoSuchKey`                                       | The object does not exist, or the target of a conditional write does not exist                                                                                                        | Check the case, directory, and URL encoding of the object key                                                 |
| 400    | `KeyTooLongError`                                 | The object key exceeds 1024 bytes                                                                                                                                                     | Shorten the key. Non-ASCII characters count as their UTF-8 byte length                                        |
| 400    | `Invalid URI`                                     | The object key contains non-printable characters, or has a path segment that is entirely `.` or `..`                                                                                  | Rename it. See [Object key rules](https://docs.bitiful.com/en/developer/s3/compatibility.md#object-key-rules) |
| 400    | `InvalidDigest`                                   | The `Content-MD5` format is invalid. It is also returned when `Cache-Control` cannot be parsed                                                                                        | Check these two headers                                                                                       |
| 400    | `BadDigest`                                       | The content does not match `Content-MD5` or the checksum                                                                                                                              | The network or your program altered the content; upload again                                                 |
| 400    | `MalformedDate`                                   | The date format is invalid, for example in the `Expires` header                                                                                                                       | Use the HTTP date format                                                                                      |
| 400    | `EntityTooLarge`                                  | The size limit is exceeded                                                                                                                                                            | See [Limits](https://docs.bitiful.com/en/bitiful-s4/limits.md)                                                |
| 400    | `EntityTooSmall`                                  | A part is smaller than 5 MiB (except the last part), or a form upload is smaller than the required size                                                                               | Increase the part size                                                                                        |
| 404    | `NoSuchUpload`                                    | The multipart upload does not exist, has completed or been aborted, or `uploadId` does not match the object key                                                                       | Create a new multipart upload                                                                                 |
| 400    | `InvalidPart`                                     | A part does not exist, an ETag does not match, or all parts are empty                                                                                                                 | Check with ListParts, then retry                                                                              |
| 400    | `InvalidArgument`                                 | An invalid argument. Common causes: the copy source does not exist, a batch delete has more than 1000 keys, a part number is out of range, or a media processing parameter is invalid | Read the `Message`                                                                                            |
| 400    | `MalformedXML`                                    | The request body XML is invalid                                                                                                                                                       | Check the XML                                                                                                 |
| 400    | `InvalidTag`                                      | A tag is invalid                                                                                                                                                                      | Up to 10 tags; keys up to 128, values up to 256                                                               |
| 400    | `InvalidCopyDest`、`InvalidCopyType`               | Copying onto itself without changing metadata, or the source or destination is a directory                                                                                            | Change the parameters                                                                                         |
| 400    | `InvalidMoveDest`、`InvalidMoveType`               | The move destination is invalid, or the source or destination is a directory                                                                                                          | Change the parameters                                                                                         |
| 409    | `ExistingObjectIsFile`                            | A file with the same name already exists at the destination or in a parent path                                                                                                       | A file and a directory cannot share a name                                                                    |
| 409    | `ExistingObjectIsDirectory`                       | A directory with the same name already exists at the destination                                                                                                                      | A file and a directory cannot share a name                                                                    |
| 409    | `OperationAborted`                                | Conflicts with a concurrent write                                                                                                                                                     | Wait and retry                                                                                                |
| 412    | `PreconditionFailed`                              | The condition does not hold                                                                                                                                                           | See [Conditional requests](https://docs.bitiful.com/en/developer/s3/conditional-requests.md)                  |
| 400    | `PostPolicyInvalidKeyName`、`MalformedPOSTRequest` | The policy or form format of a form upload is invalid                                                                                                                                 | Check the form fields                                                                                         |
| 499    | `ClientCanceled`                                  | The client disconnected or stopped sending                                                                                                                                            | Check client timeouts and the network                                                                         |

## Media processing and mirror back-to-origin

| Status | Code                                     | Meaning                                                                       | What to do                                                                                                           |
| ------ | ---------------------------------------- | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| 403    | `TooLargeForCoreIX`                      | The original file exceeds 200 MiB (video and frame extraction excepted)       | Compress the original file first                                                                                     |
| 415    | `UnsupportedMediaType`、`UnSupportedType` | The file type cannot be processed, or processing was requested on a directory | See [Supported formats](https://docs.bitiful.com/en/formats.md)                                                      |
| 400    | `InvalidArgument`                        | A processing parameter is invalid                                             | Read the `Message` and check the [CoreIX parameters](https://docs.bitiful.com/en/coreix/basic.md)                    |
| 424    | `MirrorFailed`                           | The mirror origin did not return 200, 206, or 404                             | Check the origin and the [mirror back-to-origin](https://docs.bitiful.com/en/bitiful-s4/handbook/mirror.md) settings |
| 202    | `MirrorFetching`                         | The object is being fetched from the origin and is temporarily unavailable    | Retry later                                                                                                          |

## Rate limiting and server errors

| Status | Code                 | Meaning                                                                               | What to do                                                                            |
| ------ | -------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| 429    | `TooManyRequest`     | Too many concurrent requests                                                          | Lower the concurrency and retry with exponential backoff                              |
| 500    | `InternalError`      | Server error                                                                          | Retry with backoff. For write requests, confirm the result before retrying            |
| 502    | `BadGateway`         | The backend is temporarily unreachable                                                | Retry with backoff                                                                    |
| 503    | `ServiceUnavailable` | The service is temporarily unavailable                                                | Retry with backoff                                                                    |
| 501    | `NotImplemented`     | The feature is not implemented, for example a `delimiter` other than `/` in a listing | See [S3 API compatibility](https://docs.bitiful.com/en/developer/s3/compatibility.md) |
| 405    | `MethodNotAllowed`   | The request method does not match the path                                            | Check the method and the URL                                                          |

> **Note**
>
> S4 rate limiting returns 429 `TooManyRequest`, not AWS's 503 `SlowDown`. Some SDKs do not retry this error code automatically, so handle 429 in your program.

## SignatureDoesNotMatch checklist

Check in order:

1. **Keys.** Check whether the SecretKey has extra spaces or line breaks copied with it, and whether it pairs with the AccessKey.
2. **Method.** The method of a presigned link must match the request method. A link generated for GET works only for GET and HEAD.
3. **The URL was modified.** You cannot add or remove parameters after signing, including tracking parameters, CoreIX parameters, and `x-amz-limit-rate`.
4. **The URL was escaped.** When a link is written into HTML or logs, `&` may become `&amp;` and `%2F` may become `%252F`.
5. **Content-Type.** If `content-type` was signed when the upload link was generated, the upload must match it exactly. Browsers may add `charset` automatically.
6. **Host.** A reverse proxy must not rewrite the Host header. Have the client access the bucket domain directly.
7. **Headers rewritten by a proxy.** If a proxy modifies a header that is part of the signature (for example `Accept-Encoding`), the signature becomes invalid.
8. **Object key encoding.** When signing by hand, encode spaces as `%20` instead of `+`, and encode Chinese characters as UTF-8.
9. **Signature version.** Use V4, set the Region to `cn-east-1`, and use `s3` as the service name.
10. **SDK too old.** Upgrade to a recent version, or follow the configuration in the [examples for each language](https://docs.bitiful.com/en/developer/sdk/intro.md).

## AccessDenied checklist

**Signed requests**

1. Check whether the sub-user has the matching permission on this bucket or directory. A new sub-user has no permissions by default; see [Sub-user permissions](https://docs.bitiful.com/en/bitiful-s4/handbook/permissions.md).
2. Check whether the directory grant covers this object key.
3. Listing requires list permission, and reading or writing files requires read or write permission; they are separate.
4. Copying requires read permission on the source and write permission on the destination. Moving also requires write permission on the source.
5. Writes with conditions such as `If-Match` also require read permission.
6. You cannot create or delete buckets with a sub-user AccessKey.
7. The object that the watermark image `mark` points to also needs read permission.

**Anonymous access**

1. Check whether the bucket or directory is set to [public read](https://docs.bitiful.com/en/bitiful-s4/handbook/public-read.md).
2. Check whether the request was denied by the IP, Referer, or Headers lists in [access control](https://docs.bitiful.com/en/bitiful-s4/handbook/anti-leech.md). A list denial has no dedicated error code; it is also `AccessDenied`.
3. Anonymous access to a nonexistent object also returns 403 when there is no public read; it does not return 404.

## Retry recommendations

| Can retry                                      | Do not retry as is |
| ---------------------------------------------- | ------------------ |
| 429, 500, 502, 503, and 409 `OperationAborted` | Other 4XX          |
| Network timeout, connection reset              | 412                |

Retry with exponential backoff plus random jitter, for example 0.5 seconds, 1 second, 2 seconds, up to 5 times. Mainstream SDKs have this built in, so you usually only need to add 429.
