aws-sdk#AWSError TypeScript Examples
The following examples show how to use
aws-sdk#AWSError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: s3.ts From excalidraw-json with MIT License | 6 votes |
export async function get(id: string) {
try {
const objectParams = {
Key: id,
Bucket: BUCKET_NAME,
};
const data = await s3.getObject(objectParams).promise();
return data.Body;
} catch (error: unknown) {
if ((error as AWSError)?.code === 'NoSuchKey') {
return null;
}
throw error;
}
}
Example #2
Source File: errors.ts From dyngoose with ISC License | 6 votes |
constructor(error: AWSError, public tableClass?: ITable<any>, public queryInput?: any) {
super(error.message)
Object.assign(this, error)
Error.captureStackTrace(this, this.constructor)
this.name = error.name
if (tableClass != null) {
this.tableName = tableClass.schema.name
}
}
Example #3
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
@handlerEvent(Action.Delete)
@commonAws({ serviceName: 'CodeCommit', debug: true })
public async delete(action: Action, args: HandlerArgs<ResourceModel>, service: CodeCommit, model: ResourceModel): Promise<null> {
const { awsAccountId, logicalResourceIdentifier, region } = args.request;
let { arn, id, name } = model;
if (!arn && !id && !name) {
throw new exceptions.NotFound(this.typeName, logicalResourceIdentifier);
}
if (!arn) {
arn = Resource.formatArn(region, awsAccountId, id);
}
if (!id) {
id = Resource.extractResourceId(arn);
}
const rules = await this.listRuleTemplates(service, args.logger, { id, name }).catch((err: AWSError) => {
if (err?.code === 'ApprovalRuleTemplateDoesNotExistException') {
throw new exceptions.NotFound(this.typeName, id || logicalResourceIdentifier);
} else {
// Raise the original exception
throw err;
}
});
if (!rules.length) {
throw new exceptions.NotFound(this.typeName, id || logicalResourceIdentifier);
}
name = rules[0].name;
const request: CodeCommit.DeleteApprovalRuleTemplateInput = {
approvalRuleTemplateName: name,
};
args.logger.log({ action, message: 'before invoke deleteApprovalRuleTemplate', request });
const response = await service.deleteApprovalRuleTemplate(request).promise();
args.logger.log({ action, message: 'after invoke deleteApprovalRuleTemplate', response });
args.logger.log({ action, message: 'done' });
return Promise.resolve(null);
}
Example #4
Source File: handlers.ts From aws-resource-providers with MIT License | 6 votes |
private async checkBatchResponse(response: CodeCommitBatchResponse, logger: Logger): Promise<CodeCommitBatchResponse> {
if (response.errors?.length) {
logger.log(response.errors);
const err = Error(response.errors[0].errorMessage) as AWSError;
err.requestId = response.$response?.requestId;
err.code = response.errors[0].errorCode;
throw err;
}
return response;
}
Example #5
Source File: awsUtils.ts From aws-secrets-manager-action with MIT License | 5 votes |
getSecretValue = (secretsManagerClient: SecretsManager, secretName: string):
Promise<PromiseResult<GetSecretValueResponse, AWSError>> => {
core.debug(`Fetching '${secretName}'`)
return secretsManagerClient.getSecretValue({ SecretId: secretName }).promise()
}
Example #6
Source File: sqs-consumer.ts From sns-sqs-big-payload with Apache License 2.0 | 5 votes |
private isConnError(err: AWSError): boolean {
return err.statusCode === 403 || err.code === 'CredentialsError' || err.code === 'UnknownEndpoint';
}
Example #7
Source File: proxy.ts From cloudformation-cli-typescript-plugin with Apache License 2.0 | 5 votes |
private extendAwsClient<
S extends Service = Service,
C extends Constructor<S> = Constructor<S>,
O extends ServiceProperties<S, C> = ServiceProperties<S, C>,
E extends Error = AWSError,
N extends ServiceOperation<S, C, O, E> = ServiceOperation<S, C, O, E>
>(
service: S,
options?: ServiceConfigurationOptions,
workerPool?: AwsTaskWorkerPool
): ExtendedClient<S> {
const client: ExtendedClient<S> = new Proxy(service, {
get(obj: ExtendedClient<S>, prop: string) {
if ('makeRequestPromise' === prop) {
// Extend AWS client with promisified make request method
// that can be used with worker pool
return async (
operation: O,
input?: OverloadedArguments<N>,
headers?: Record<string, string>
): Promise<InferredResult<S, C, O, E, N>> => {
if (workerPool && workerPool.runAwsTask) {
try {
const result = await workerPool.runAwsTask<
S,
C,
O,
E,
N
>({
name: obj.serviceIdentifier,
options,
operation,
input,
headers,
});
return result;
} catch (err) {
console.log(err);
}
}
const request = obj.makeRequest(operation as string, input);
const headerEntries = Object.entries(headers || {});
if (headerEntries.length) {
request.on('build', () => {
for (const [key, value] of headerEntries) {
request.httpRequest.headers[key] = value;
}
});
}
return await request.promise();
};
}
return obj[prop];
},
});
if (client.config && client.config.update) {
client.config.update(options);
}
return client;
}
Example #8
Source File: result-model.ts From serverless-typescript-monorepo-example with MIT License | 5 votes |
fromAwsError = <R>(error: AWSError): Result<R> => {
return failure(error.message);
}
Example #9
Source File: index.ts From electify with MIT License | 5 votes |
error = (err: AWSError, res: NextApiResponse) => {
console.log(err);
res.json({ success: false, error: true });
}
Example #10
Source File: [election_id].ts From electify with MIT License | 5 votes |
error = (_: AWSError, res: NextApiResponse) => {
res.json({ success: false, error: true });
}