Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix JSdoc for errors, rename error base class to S3Error #32

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions errors.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
/**
* @module
* All the errors which can be thrown by this S3 client.
* Every error is a subclass of S3Error.
*/

import { parse as parseXML } from "./xml-parser.ts";

/**
* Base class for all errors raised by this S3 client.
*/
export class DenoS3LiteClientError extends Error {
export class S3Error extends Error {
constructor(message: string) {
super(message);
}
}

// Preserve API compatibility with the old name:
export const DenoS3LiteClientError = S3Error;

/**
* An argument or configuration parameter was invalid.
*/
export class InvalidArgumentError extends DenoS3LiteClientError {}
export class InvalidArgumentError extends S3Error {}

/**
* InvalidEndpointError is generated when an invalid end point value is
* provided which does not follow domain standards.
*/
export class InvalidEndpointError extends DenoS3LiteClientError {}
export class InvalidEndpointError extends S3Error {}

/**
* InvalidBucketNameError is generated when an invalid bucket name is
* provided which does not follow AWS S3 specifications.
* http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
*/
export class InvalidBucketNameError extends DenoS3LiteClientError {}
export class InvalidBucketNameError extends S3Error {}

/**
* InvalidObjectNameError is generated when an invalid object name is
* provided which does not follow AWS S3 specifications.
* http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
*/
export class InvalidObjectNameError extends DenoS3LiteClientError {}
export class InvalidObjectNameError extends S3Error {}

/** The request cannot be made without an access key to authenticate it */
export class AccessKeyRequiredError extends DenoS3LiteClientError {}
export class AccessKeyRequiredError extends S3Error {}

/** The request cannot be made without a secret key to authenticate it */
export class SecretKeyRequiredError extends DenoS3LiteClientError {}
export class SecretKeyRequiredError extends S3Error {}

/** The expiration time for the request is invalid */
export class InvalidExpiryError extends DenoS3LiteClientError {}
export class InvalidExpiryError extends S3Error {}

/** Any error thrown by the server */
export class ServerError extends DenoS3LiteClientError {
export class ServerError extends S3Error {
readonly statusCode: number;
readonly code: string;
readonly key: string | undefined;
Expand All @@ -68,6 +77,7 @@ export class ServerError extends DenoS3LiteClientError {
}
}

/** Helper function to parse an error returned by the S3 server. */
export async function parseServerError(response: Response): Promise<ServerError> {
try {
const xmlParsed = parseXML(await response.text());
Expand Down
5 changes: 0 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@
*/

export { Client as S3Client } from "./client.ts";

/**
* @namespace
* Namespace for all errors that can be thrown by S3Client
*/
export * as S3Errors from "./errors.ts";