dimah-s3v1.3.0

Errors

Stable error codes, error helpers, and APIError handling.

All failed requests return JSON { message, code?, params? } and standard HTTP status codes.

Use the errors helper to throw standard library errors:

import { APIError, errors, isAPIError, isS3ErrorCode } from "@dimah-s3/server";

// Standard helpers
throw errors.unauthorized();
throw errors.forbidden();
throw errors.objectNotFound();
throw errors.payloadTooLarge();
throw errors.featureDisabled("download");
throw errors.unknownRoute("avatar");
throw errors.fileTypeNotAllowed("application/zip");

// Custom APIError
throw new APIError("BAD_REQUEST", {
  message: "Invalid file payload.",
});

Catch and inspect errors:

if (isAPIError(err)) {
  console.log(err.status, err.statusCode, err.code, err.message);
}

if (isS3ErrorCode(err, "OBJECT_NOT_FOUND")) {
  // Handle missing object specifically
}

Error catalog

codeHTTPTrigger
NOT_FOUND404Unknown API path
UNKNOWN_ROUTE404Target route is not registered on the server (params.route)
FEATURE_DISABLED404Target operation (upload, download, delete) is not enabled on this route
OBJECT_NOT_FOUND404Object key or multipart upload does not exist
UNAUTHORIZED401Thrown by your auth guards (errors.unauthorized())
FORBIDDEN403Guard rejection or generic unhandled Error inside guards
CONFLICT409Resource conflict in lifecycle hooks
PAYLOAD_TOO_LARGE413File size exceeds route maxFileSize (at presign, part upload, or HeadObject)
FILE_TYPE_NOT_ALLOWED400File type not allowed by route fileTypes
VALIDATION_ERROR400Invalid payload shape or malformed checksum
INVALID_KEY400Unsafe key or key outside route keyPrefix
MULTIPART_PART_MISSING400Complete payload references missing part numbers
S3_NETWORK_ERROR502S3 storage service unreachable
INTERNAL_ERROR500Unhandled server exception or failed on* hook

Frequently asked questions

On this page