Skip to content

Commit

Permalink
docs: fix JSdoc for errors, rename error base class to S3Error
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Mar 3, 2024
1 parent ea81a4e commit 687dace
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
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";

0 comments on commit 687dace

Please sign in to comment.