From 304ca3eeeea13634ce491e636a86b3e28fcc3d06 Mon Sep 17 00:00:00 2001 From: George Fu Date: Wed, 6 Mar 2024 17:25:00 -0500 Subject: [PATCH] chore(codegen): use lib serde helpers instead of codegen (#5855) * chore(codegen): use lib serde helpers instead of codegen * feat: write error.$responseBodyText if available * chore: codegen update to use imported serde helper functions * chore: unused imports --- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-acm/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-amp/src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- clients/client-auto-scaling/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../client-b2bi/src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- clients/client-cloudformation/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- clients/client-cloudfront/package.json | 1 - .../src/protocols/Aws_restXml.ts | 47 +------------ .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- clients/client-cloudsearch/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- clients/client-cloudwatch/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../client-dax/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-dlm/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- clients/client-docdb/package.json | 1 - .../client-docdb/src/protocols/Aws_query.ts | 38 +--------- .../client-drs/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../client-ebs/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- clients/client-ec2/package.json | 1 - clients/client-ec2/src/protocols/Aws_ec2.ts | 38 +--------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-ecr/src/protocols/Aws_json1_1.ts | 52 +------------- .../client-ecs/src/protocols/Aws_json1_1.ts | 52 +------------- .../client-efs/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-eks/src/protocols/Aws_restJson1.ts | 52 +------------- clients/client-elastic-beanstalk/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- clients/client-elasticache/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../client-emr/src/protocols/Aws_json1_1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-fis/src/protocols/Aws_restJson1.ts | 52 +------------- .../client-fms/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../client-fsx/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-glue/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- clients/client-iam/package.json | 1 - clients/client-iam/src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-iot/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-ivs/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-kms/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-m2/src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-mgn/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-mq/src/protocols/Aws_restJson1.ts | 52 +------------- .../client-mturk/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- clients/client-neptune/package.json | 1 - .../client-neptune/src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-oam/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-pi/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../client-ram/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- clients/client-rds/package.json | 1 - clients/client-rds/src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_json1_1.ts | 58 ++------------- .../src/protocols/Aws_json1_1.ts | 58 ++------------- clients/client-redshift/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- clients/client-route-53/package.json | 1 - .../src/protocols/Aws_restXml.ts | 47 +------------ .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-rum/src/protocols/Aws_restJson1.ts | 52 +------------- clients/client-s3-control/package.json | 1 - .../src/protocols/Aws_restXml.ts | 47 +------------ clients/client-s3/package.json | 1 - .../client-s3/src/protocols/Aws_restXml.ts | 47 +------------ .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- clients/client-ses/package.json | 1 - clients/client-ses/src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-sfn/src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-sms/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- clients/client-sns/package.json | 1 - clients/client-sns/src/protocols/Aws_query.ts | 38 +--------- .../client-sqs/src/protocols/Aws_json1_0.ts | 60 +++------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-ssm/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../client-sso/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- clients/client-sts/package.json | 1 - clients/client-sts/src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-swf/src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../client-tnb/src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_json1_0.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../client-waf/src/protocols/Aws_json1_1.ts | 52 +------------- .../client-wafv2/src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 52 +------------- .../src/protocols/Aws_json1_1.ts | 52 +------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../typescript/codegen/AwsProtocolUtils.java | 70 ++----------------- .../aws/typescript/codegen/AwsRestXml.java | 19 +---- .../codegen/JsonRpcProtocolGenerator.java | 3 +- .../codegen/RestJsonProtocolGenerator.java | 3 +- packages/core/src/protocols/common.ts | 5 ++ packages/core/src/protocols/index.ts | 2 + .../core/src/protocols/json/parseJsonBody.ts | 32 +++++++-- .../core/src/protocols/xml/parseXmlBody.ts | 64 +++++++++++++++++ .../src/protocols/Aws_restJson1.ts | 52 +------------- private/aws-protocoltests-ec2/package.json | 1 - .../src/protocols/Aws_ec2.ts | 38 +--------- .../src/protocols/Aws_json1_0.ts | 58 ++------------- .../src/protocols/Aws_json1_1.ts | 58 ++------------- private/aws-protocoltests-query/package.json | 1 - .../src/protocols/Aws_query.ts | 38 +--------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restXml.ts | 47 +------------ .../src/protocols/Aws_restJson1.ts | 58 ++------------- .../src/protocols/Aws_restJson1.ts | 58 ++------------- 419 files changed, 811 insertions(+), 19675 deletions(-) create mode 100644 packages/core/src/protocols/common.ts rename codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/load-json-error-code-stub.ts => packages/core/src/protocols/json/parseJsonBody.ts (52%) create mode 100644 packages/core/src/protocols/xml/parseXmlBody.ts diff --git a/clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts b/clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts index 911bb4df68b68..b6a3e95b92eae 100644 --- a/clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts +++ b/clients/client-accessanalyzer/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2452,54 +2457,3 @@ const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _t = "type"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-account/src/protocols/Aws_restJson1.ts b/clients/client-account/src/protocols/Aws_restJson1.ts index 4fbb2ee33ee8d..1d51ed20f8615 100644 --- a/clients/client-account/src/protocols/Aws_restJson1.ts +++ b/clients/client-account/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -626,54 +627,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-acm-pca/src/protocols/Aws_json1_1.ts b/clients/client-acm-pca/src/protocols/Aws_json1_1.ts index 83d0e995bea18..955abf885b53e 100644 --- a/clients/client-acm-pca/src/protocols/Aws_json1_1.ts +++ b/clients/client-acm-pca/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1639,54 +1640,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `ACMPrivateCA.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-acm/src/protocols/Aws_json1_1.ts b/clients/client-acm/src/protocols/Aws_json1_1.ts index a060e0f3c0805..a5cad6dc0dfe1 100644 --- a/clients/client-acm/src/protocols/Aws_json1_1.ts +++ b/clients/client-acm/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1178,54 +1179,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CertificateManager.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-alexa-for-business/src/protocols/Aws_json1_1.ts b/clients/client-alexa-for-business/src/protocols/Aws_json1_1.ts index 8c84480ce13ff..2219e96ba7571 100644 --- a/clients/client-alexa-for-business/src/protocols/Aws_json1_1.ts +++ b/clients/client-alexa-for-business/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4730,54 +4731,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AlexaForBusiness.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-amp/src/protocols/Aws_restJson1.ts b/clients/client-amp/src/protocols/Aws_restJson1.ts index d5f2808097361..a775f08eb659f 100644 --- a/clients/client-amp/src/protocols/Aws_restJson1.ts +++ b/clients/client-amp/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1642,54 +1647,3 @@ const _nT = "nextToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-amplify/src/protocols/Aws_restJson1.ts b/clients/client-amplify/src/protocols/Aws_restJson1.ts index c3fb1d10efdc9..8e9da15f4d56b 100644 --- a/clients/client-amplify/src/protocols/Aws_restJson1.ts +++ b/clients/client-amplify/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2209,54 +2210,3 @@ const _eN = "environmentName"; const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-amplifybackend/src/protocols/Aws_restJson1.ts b/clients/client-amplifybackend/src/protocols/Aws_restJson1.ts index 24e5362face46..506189ac965d1 100644 --- a/clients/client-amplifybackend/src/protocols/Aws_restJson1.ts +++ b/clients/client-amplifybackend/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2468,54 +2469,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-amplifyuibuilder/src/protocols/Aws_restJson1.ts b/clients/client-amplifyuibuilder/src/protocols/Aws_restJson1.ts index 50308269dbcb3..5175e9d170688 100644 --- a/clients/client-amplifyuibuilder/src/protocols/Aws_restJson1.ts +++ b/clients/client-amplifyuibuilder/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2744,54 +2749,3 @@ const _cT = "clientToken"; const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-api-gateway/src/protocols/Aws_restJson1.ts b/clients/client-api-gateway/src/protocols/Aws_restJson1.ts index 70ef85ab9fa13..749f99dfec6b6 100644 --- a/clients/client-api-gateway/src/protocols/Aws_restJson1.ts +++ b/clients/client-api-gateway/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -6513,54 +6514,3 @@ const _ra = "retry-after"; const _sD = "startDate"; const _t = "type"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-apigatewaymanagementapi/src/protocols/Aws_restJson1.ts b/clients/client-apigatewaymanagementapi/src/protocols/Aws_restJson1.ts index 35044010c2c62..42fa6aba577b1 100644 --- a/clients/client-apigatewaymanagementapi/src/protocols/Aws_restJson1.ts +++ b/clients/client-apigatewaymanagementapi/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -271,54 +272,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-apigatewayv2/src/protocols/Aws_restJson1.ts b/clients/client-apigatewayv2/src/protocols/Aws_restJson1.ts index 214dedcc81bfb..98c43922b4094 100644 --- a/clients/client-apigatewayv2/src/protocols/Aws_restJson1.ts +++ b/clients/client-apigatewayv2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4374,54 +4375,3 @@ const _nT = "nextToken"; const _oT = "outputType"; const _sN = "stageName"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-app-mesh/src/protocols/Aws_restJson1.ts b/clients/client-app-mesh/src/protocols/Aws_restJson1.ts index 158d96d1d9732..608b43aa0d5a2 100644 --- a/clients/client-app-mesh/src/protocols/Aws_restJson1.ts +++ b/clients/client-app-mesh/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3011,54 +3012,3 @@ const _l = "limit"; const _mO = "meshOwner"; const _nT = "nextToken"; const _rA = "resourceArn"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-appconfig/src/protocols/Aws_restJson1.ts b/clients/client-appconfig/src/protocols/Aws_restJson1.ts index 45a3649e85b08..72e4d8561041b 100644 --- a/clients/client-appconfig/src/protocols/Aws_restJson1.ts +++ b/clients/client-appconfig/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2497,54 +2502,3 @@ const _ve = "version"; const _vl = "version_label"; const _vn = "version_number"; const _vn_ = "version-number"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-appconfigdata/src/protocols/Aws_restJson1.ts b/clients/client-appconfigdata/src/protocols/Aws_restJson1.ts index 490b04c5e9936..e6cda474d321e 100644 --- a/clients/client-appconfigdata/src/protocols/Aws_restJson1.ts +++ b/clients/client-appconfigdata/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -271,54 +276,3 @@ const _ct_ = "content-type"; const _npct = "next-poll-configuration-token"; const _npiis = "next-poll-interval-in-seconds"; const _vl = "version-label"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-appfabric/src/protocols/Aws_restJson1.ts b/clients/client-appfabric/src/protocols/Aws_restJson1.ts index 4d62ca78fbf4c..1c860af4728d9 100644 --- a/clients/client-appfabric/src/protocols/Aws_restJson1.ts +++ b/clients/client-appfabric/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1563,54 +1568,3 @@ const _nT = "nextToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-appflow/src/protocols/Aws_restJson1.ts b/clients/client-appflow/src/protocols/Aws_restJson1.ts index daf29eba1bc2d..e27a89ad93360 100644 --- a/clients/client-appflow/src/protocols/Aws_restJson1.ts +++ b/clients/client-appflow/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2465,54 +2466,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-appintegrations/src/protocols/Aws_restJson1.ts b/clients/client-appintegrations/src/protocols/Aws_restJson1.ts index 08c603feecfba..cf3819d302429 100644 --- a/clients/client-appintegrations/src/protocols/Aws_restJson1.ts +++ b/clients/client-appintegrations/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1328,54 +1329,3 @@ const _NT = "NextToken"; const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-application-auto-scaling/src/protocols/Aws_json1_1.ts b/clients/client-application-auto-scaling/src/protocols/Aws_json1_1.ts index ceaf60f877980..31cf319403ef4 100644 --- a/clients/client-application-auto-scaling/src/protocols/Aws_json1_1.ts +++ b/clients/client-application-auto-scaling/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1195,54 +1196,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AnyScaleFrontendService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-application-discovery-service/src/protocols/Aws_json1_1.ts b/clients/client-application-discovery-service/src/protocols/Aws_json1_1.ts index 2ccbb022c2987..ba448e22c4f52 100644 --- a/clients/client-application-discovery-service/src/protocols/Aws_json1_1.ts +++ b/clients/client-application-discovery-service/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1849,54 +1850,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSPoseidonService_V2015_11_01.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-application-insights/src/protocols/Aws_json1_1.ts b/clients/client-application-insights/src/protocols/Aws_json1_1.ts index f0dbfe217a15d..bc0b640120507 100644 --- a/clients/client-application-insights/src/protocols/Aws_json1_1.ts +++ b/clients/client-application-insights/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1831,54 +1832,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `EC2WindowsBarleyService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-applicationcostprofiler/src/protocols/Aws_restJson1.ts b/clients/client-applicationcostprofiler/src/protocols/Aws_restJson1.ts index a22dc7e77fb97..e614c707d374c 100644 --- a/clients/client-applicationcostprofiler/src/protocols/Aws_restJson1.ts +++ b/clients/client-applicationcostprofiler/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -500,54 +501,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _mR = "maxResults"; const _nT = "nextToken"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-apprunner/src/protocols/Aws_json1_0.ts b/clients/client-apprunner/src/protocols/Aws_json1_0.ts index c1a7b9442aa45..bce7c50fab7dd 100644 --- a/clients/client-apprunner/src/protocols/Aws_json1_0.ts +++ b/clients/client-apprunner/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2331,54 +2332,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AppRunner.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-appstream/src/protocols/Aws_json1_1.ts b/clients/client-appstream/src/protocols/Aws_json1_1.ts index 225516336d6bc..529c8c1630323 100644 --- a/clients/client-appstream/src/protocols/Aws_json1_1.ts +++ b/clients/client-appstream/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4364,54 +4365,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `PhotonAdminProxyService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-appsync/src/protocols/Aws_restJson1.ts b/clients/client-appsync/src/protocols/Aws_restJson1.ts index 763fd8a670857..977526185316a 100644 --- a/clients/client-appsync/src/protocols/Aws_restJson1.ts +++ b/clients/client-appsync/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3471,54 +3472,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _o = "owner"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-arc-zonal-shift/src/protocols/Aws_restJson1.ts b/clients/client-arc-zonal-shift/src/protocols/Aws_restJson1.ts index 67ed045f5c970..3b9b00ce1e64a 100644 --- a/clients/client-arc-zonal-shift/src/protocols/Aws_restJson1.ts +++ b/clients/client-arc-zonal-shift/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -904,54 +905,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _rI = "resourceIdentifier"; const _s = "status"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-artifact/src/protocols/Aws_restJson1.ts b/clients/client-artifact/src/protocols/Aws_restJson1.ts index 8963fe9293993..91526b9b2b68a 100644 --- a/clients/client-artifact/src/protocols/Aws_restJson1.ts +++ b/clients/client-artifact/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -569,54 +570,3 @@ const _rI = "reportId"; const _rV = "reportVersion"; const _ra = "retry-after"; const _tT = "termToken"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-athena/src/protocols/Aws_json1_1.ts b/clients/client-athena/src/protocols/Aws_json1_1.ts index b9bfd74a8740b..3034fbaabc069 100644 --- a/clients/client-athena/src/protocols/Aws_json1_1.ts +++ b/clients/client-athena/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3807,54 +3808,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonAthena.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-auditmanager/src/protocols/Aws_restJson1.ts b/clients/client-auditmanager/src/protocols/Aws_restJson1.ts index 4852831382773..3ff838a8ab874 100644 --- a/clients/client-auditmanager/src/protocols/Aws_restJson1.ts +++ b/clients/client-auditmanager/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3836,54 +3837,3 @@ const _rT = "requestType"; const _s = "status"; const _so = "source"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-auto-scaling-plans/src/protocols/Aws_json1_1.ts b/clients/client-auto-scaling-plans/src/protocols/Aws_json1_1.ts index c13081dc789fa..5b6c66560e902 100644 --- a/clients/client-auto-scaling-plans/src/protocols/Aws_json1_1.ts +++ b/clients/client-auto-scaling-plans/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -808,54 +809,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AnyScaleScalingPlannerFrontendService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-auto-scaling/package.json b/clients/client-auto-scaling/package.json index b264627ae0d12..294e009f67fab 100644 --- a/clients/client-auto-scaling/package.json +++ b/clients/client-auto-scaling/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-auto-scaling/src/protocols/Aws_query.ts b/clients/client-auto-scaling/src/protocols/Aws_query.ts index 681e3bed26096..5e80b32c59192 100644 --- a/clients/client-auto-scaling/src/protocols/Aws_query.ts +++ b/clients/client-auto-scaling/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, serializeFloat as __serializeFloat, @@ -21,7 +21,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AttachInstancesCommandInput, AttachInstancesCommandOutput } from "../commands/AttachInstancesCommand"; import { @@ -9749,41 +9748,6 @@ const _WPS = "WarmPoolSize"; const _m = "message"; const _me = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-b2bi/src/protocols/Aws_json1_0.ts b/clients/client-b2bi/src/protocols/Aws_json1_0.ts index 56428a5751d07..eba424971c826 100644 --- a/clients/client-b2bi/src/protocols/Aws_json1_0.ts +++ b/clients/client-b2bi/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1709,54 +1714,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `B2BI.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-backup-gateway/src/protocols/Aws_json1_0.ts b/clients/client-backup-gateway/src/protocols/Aws_json1_0.ts index 6bcde5e8ba8d0..baaf290f5b5e2 100644 --- a/clients/client-backup-gateway/src/protocols/Aws_json1_0.ts +++ b/clients/client-backup-gateway/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1414,54 +1415,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `BackupOnPremises_v20210101.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-backup/src/protocols/Aws_restJson1.ts b/clients/client-backup/src/protocols/Aws_restJson1.ts index c4bbccd5f2fbc..f886890cd10a3 100644 --- a/clients/client-backup/src/protocols/Aws_restJson1.ts +++ b/clients/client-backup/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -5483,54 +5484,3 @@ const _sh = "shared"; const _st = "status"; const _vI = "versionId"; const _vT = "vaultType"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-backupstorage/src/protocols/Aws_restJson1.ts b/clients/client-backupstorage/src/protocols/Aws_restJson1.ts index f66472cd42409..390884c4fbd26 100644 --- a/clients/client-backupstorage/src/protocols/Aws_restJson1.ts +++ b/clients/client-backupstorage/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -768,54 +769,3 @@ const _xac = "x-amz-checksum"; const _xaca = "x-amz-checksum-algorithm"; const _xadl = "x-amz-data-length"; const _xams = "x-amz-metadata-string"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-batch/src/protocols/Aws_restJson1.ts b/clients/client-batch/src/protocols/Aws_restJson1.ts index 04ad1be37d9ff..4ca54d28f2ba5 100644 --- a/clients/client-batch/src/protocols/Aws_restJson1.ts +++ b/clients/client-batch/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1934,54 +1935,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-bcm-data-exports/src/protocols/Aws_json1_1.ts b/clients/client-bcm-data-exports/src/protocols/Aws_json1_1.ts index acf99e9a1528b..f3d17f98c2504 100644 --- a/clients/client-bcm-data-exports/src/protocols/Aws_json1_1.ts +++ b/clients/client-bcm-data-exports/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -838,54 +839,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSBillingAndCostManagementDataExports.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts b/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts index 80ea152ba27d2..d5d11b3179169 100644 --- a/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -850,54 +855,3 @@ const _cT = "contentType"; const _sI = "sessionId"; const _xabact = "x-amzn-bedrock-agent-content-type"; const _xabasi = "x-amz-bedrock-agent-session-id"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-bedrock-agent/src/protocols/Aws_restJson1.ts b/clients/client-bedrock-agent/src/protocols/Aws_restJson1.ts index 78e7b5449d740..0266aa695a87b 100644 --- a/clients/client-bedrock-agent/src/protocols/Aws_restJson1.ts +++ b/clients/client-bedrock-agent/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2702,54 +2707,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _sRIUC = "skipResourceInUseCheck"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts b/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts index 72248344fd37f..c8ca124df31ed 100644 --- a/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -492,54 +493,3 @@ const _cT = "contentType"; const _ct = "content-type"; const _xaba = "x-amzn-bedrock-accept"; const _xabct = "x-amzn-bedrock-content-type"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-bedrock/src/protocols/Aws_restJson1.ts b/clients/client-bedrock/src/protocols/Aws_restJson1.ts index 4960a1c66ab79..5bc84132c9d9d 100644 --- a/clients/client-bedrock/src/protocols/Aws_restJson1.ts +++ b/clients/client-bedrock/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1409,54 +1410,3 @@ const _nT = "nextToken"; const _sB = "sortBy"; const _sE = "statusEquals"; const _sO = "sortOrder"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-billingconductor/src/protocols/Aws_restJson1.ts b/clients/client-billingconductor/src/protocols/Aws_restJson1.ts index e0f7dd245dad7..b559573a077d1 100644 --- a/clients/client-billingconductor/src/protocols/Aws_restJson1.ts +++ b/clients/client-billingconductor/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2217,54 +2218,3 @@ const _TK = "TagKeys"; const _ra = "retry-after"; const _tK = "tagKeys"; const _xact = "x-amzn-client-token"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-braket/src/protocols/Aws_restJson1.ts b/clients/client-braket/src/protocols/Aws_restJson1.ts index 0bebb9c91b714..c220b38cbdea9 100644 --- a/clients/client-braket/src/protocols/Aws_restJson1.ts +++ b/clients/client-braket/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1085,54 +1086,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _aAN = "additionalAttributeNames"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-budgets/src/protocols/Aws_json1_1.ts b/clients/client-budgets/src/protocols/Aws_json1_1.ts index 19862850e9728..af44674130129 100644 --- a/clients/client-budgets/src/protocols/Aws_json1_1.ts +++ b/clients/client-budgets/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1885,54 +1886,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSBudgetServiceGateway.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-chatbot/src/protocols/Aws_restJson1.ts b/clients/client-chatbot/src/protocols/Aws_restJson1.ts index d2e33a75c8edb..62a30aadccc87 100644 --- a/clients/client-chatbot/src/protocols/Aws_restJson1.ts +++ b/clients/client-chatbot/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1882,54 +1883,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-chime-sdk-identity/src/protocols/Aws_restJson1.ts b/clients/client-chime-sdk-identity/src/protocols/Aws_restJson1.ts index d1ed6be9eb08f..5debb994e4050 100644 --- a/clients/client-chime-sdk-identity/src/protocols/Aws_restJson1.ts +++ b/clients/client-chime-sdk-identity/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1776,54 +1777,3 @@ const _aia = "app-instance-arn"; const _mr = "max-results"; const _nt = "next-token"; const _o = "operation"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-chime-sdk-media-pipelines/src/protocols/Aws_restJson1.ts b/clients/client-chime-sdk-media-pipelines/src/protocols/Aws_restJson1.ts index 1da00280dcbd3..c2b4e49e45407 100644 --- a/clients/client-chime-sdk-media-pipelines/src/protocols/Aws_restJson1.ts +++ b/clients/client-chime-sdk-media-pipelines/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2305,54 +2306,3 @@ const _a = "arn"; const _mr = "max-results"; const _nt = "next-token"; const _o = "operation"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-chime-sdk-meetings/src/protocols/Aws_restJson1.ts b/clients/client-chime-sdk-meetings/src/protocols/Aws_restJson1.ts index 65f125a3de96f..d5a0be91839e1 100644 --- a/clients/client-chime-sdk-meetings/src/protocols/Aws_restJson1.ts +++ b/clients/client-chime-sdk-meetings/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1171,54 +1172,3 @@ const _mr = "max-results"; const _nt = "next-token"; const _o = "operation"; const _ra = "retry-after"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-chime-sdk-messaging/src/protocols/Aws_restJson1.ts b/clients/client-chime-sdk-messaging/src/protocols/Aws_restJson1.ts index d322f24e27b6f..de15b8c418d8b 100644 --- a/clients/client-chime-sdk-messaging/src/protocols/Aws_restJson1.ts +++ b/clients/client-chime-sdk-messaging/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3047,54 +3048,3 @@ const _sci = "sub-channel-id"; const _so = "sort-order"; const _t = "type"; const _xacb = "x-amz-chime-bearer"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-chime-sdk-voice/src/protocols/Aws_restJson1.ts b/clients/client-chime-sdk-voice/src/protocols/Aws_restJson1.ts index 571458d77bdb2..6c3443cf8dd9a 100644 --- a/clients/client-chime-sdk-voice/src/protocols/Aws_restJson1.ts +++ b/clients/client-chime-sdk-voice/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -5088,54 +5089,3 @@ const _st = "state"; const _t = "type"; const _tfp = "toll-free-prefix"; const _vpdi = "voice-profile-domain-id"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-chime/src/protocols/Aws_restJson1.ts b/clients/client-chime/src/protocols/Aws_restJson1.ts index 931c74417b6fe..f2ac1ae9b26a5 100644 --- a/clients/client-chime/src/protocols/Aws_restJson1.ts +++ b/clients/client-chime/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -10273,54 +10274,3 @@ const _tfp = "toll-free-prefix"; const _ue = "user-email"; const _ut = "user-type"; const _xacb = "x-amz-chime-bearer"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cleanrooms/src/protocols/Aws_restJson1.ts b/clients/client-cleanrooms/src/protocols/Aws_restJson1.ts index 975b2fa3ddf3f..60bda20e8c369 100644 --- a/clients/client-cleanrooms/src/protocols/Aws_restJson1.ts +++ b/clients/client-cleanrooms/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4175,54 +4180,3 @@ const _pBT = "privacyBudgetType"; const _s = "status"; const _sT = "schemaType"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cleanroomsml/src/protocols/Aws_restJson1.ts b/clients/client-cleanroomsml/src/protocols/Aws_restJson1.ts index 24708db98d322..73a82e55e812a 100644 --- a/clients/client-cleanroomsml/src/protocols/Aws_restJson1.ts +++ b/clients/client-cleanroomsml/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1612,54 +1613,3 @@ const _cI = "collaborationId"; const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloud9/src/protocols/Aws_json1_1.ts b/clients/client-cloud9/src/protocols/Aws_json1_1.ts index 7d2bb17eae8e3..1d3fb64a3de5f 100644 --- a/clients/client-cloud9/src/protocols/Aws_json1_1.ts +++ b/clients/client-cloud9/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -864,54 +865,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSCloud9WorkspaceManagementService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudcontrol/src/protocols/Aws_json1_0.ts b/clients/client-cloudcontrol/src/protocols/Aws_json1_0.ts index 3398e84df2d5b..b304cc0e2eb85 100644 --- a/clients/client-cloudcontrol/src/protocols/Aws_json1_0.ts +++ b/clients/client-cloudcontrol/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -993,54 +994,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CloudApiService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-clouddirectory/src/protocols/Aws_restJson1.ts b/clients/client-clouddirectory/src/protocols/Aws_restJson1.ts index ce3103fa80dcb..9d504ee687251 100644 --- a/clients/client-clouddirectory/src/protocols/Aws_restJson1.ts +++ b/clients/client-clouddirectory/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -5045,54 +5050,3 @@ const _DSA = "DevelopmentSchemaArn"; const _SA = "SchemaArn"; const _xacl = "x-amz-consistency-level"; const _xadp = "x-amz-data-partition"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudformation/package.json b/clients/client-cloudformation/package.json index 6f36f90862765..ede13942763d6 100644 --- a/clients/client-cloudformation/package.json +++ b/clients/client-cloudformation/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0", "uuid": "^9.0.1" }, diff --git a/clients/client-cloudformation/src/protocols/Aws_query.ts b/clients/client-cloudformation/src/protocols/Aws_query.ts index 8dc95931ad0cc..cfba599faa9ec 100644 --- a/clients/client-cloudformation/src/protocols/Aws_query.ts +++ b/clients/client-cloudformation/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseFloat as __strictParseFloat, @@ -20,7 +20,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { v4 as generateIdempotencyToken } from "uuid"; import { @@ -11328,41 +11327,6 @@ const _W = "Warnings"; const _e = "entry"; const _m = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-cloudfront-keyvaluestore/src/protocols/Aws_restJson1.ts b/clients/client-cloudfront-keyvaluestore/src/protocols/Aws_restJson1.ts index 944327c5333ab..980c8b4da1b94 100644 --- a/clients/client-cloudfront-keyvaluestore/src/protocols/Aws_restJson1.ts +++ b/clients/client-cloudfront-keyvaluestore/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -494,54 +495,3 @@ const _MR = "MaxResults"; const _NT = "NextToken"; const _e = "etag"; const _im = "if-match"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudfront/package.json b/clients/client-cloudfront/package.json index 95c2128087612..56ba9be9a63f2 100644 --- a/clients/client-cloudfront/package.json +++ b/clients/client-cloudfront/package.json @@ -60,7 +60,6 @@ "@smithy/util-stream": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-cloudfront/src/protocols/Aws_restXml.ts b/clients/client-cloudfront/src/protocols/Aws_restXml.ts index 8a30e3c33700a..df61a65b8b30d 100644 --- a/clients/client-cloudfront/src/protocols/Aws_restXml.ts +++ b/clients/client-cloudfront/src/protocols/Aws_restXml.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestXmlErrorCode, parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { XmlNode as __XmlNode, XmlText as __XmlText } from "@aws-sdk/xml-builder"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; @@ -10,7 +11,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, map, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, @@ -25,7 +25,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AssociateAliasCommandInput, AssociateAliasCommandOutput } from "../commands/AssociateAliasCommand"; import { CopyDistributionCommandInput, CopyDistributionCommandOutput } from "../commands/CopyDistributionCommand"; @@ -14720,47 +14719,3 @@ const _s = "staging"; const _sST = "sensitiveStringType"; const _st = "string"; const _ve = ''; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - -const loadRestXmlErrorCode = (output: __HttpResponse, data: any): string | undefined => { - if (data.Error?.Code !== undefined) { - return data.Error.Code; - } - if (output.statusCode == 404) { - return "NotFound"; - } -}; diff --git a/clients/client-cloudhsm-v2/src/protocols/Aws_json1_1.ts b/clients/client-cloudhsm-v2/src/protocols/Aws_json1_1.ts index 358674dab22e9..a8d5554040e7a 100644 --- a/clients/client-cloudhsm-v2/src/protocols/Aws_json1_1.ts +++ b/clients/client-cloudhsm-v2/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -991,54 +992,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `BaldrApiService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudhsm/src/protocols/Aws_json1_1.ts b/clients/client-cloudhsm/src/protocols/Aws_json1_1.ts index 029b154e30eb1..120ef785a2b82 100644 --- a/clients/client-cloudhsm/src/protocols/Aws_json1_1.ts +++ b/clients/client-cloudhsm/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -959,54 +960,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CloudHsmFrontendService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudsearch-domain/src/protocols/Aws_restJson1.ts b/clients/client-cloudsearch-domain/src/protocols/Aws_restJson1.ts index 1d5aeef784d06..3c9d2bc8a0b6a 100644 --- a/clients/client-cloudsearch-domain/src/protocols/Aws_restJson1.ts +++ b/clients/client-cloudsearch-domain/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -344,54 +345,3 @@ const _so = "sort"; const _st = "start"; const _sta = "stats"; const _su = "suggester"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudsearch/package.json b/clients/client-cloudsearch/package.json index 220895a5944bb..d6158ec139988 100644 --- a/clients/client-cloudsearch/package.json +++ b/clients/client-cloudsearch/package.json @@ -57,7 +57,6 @@ "@smithy/util-middleware": "^2.1.3", "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-cloudsearch/src/protocols/Aws_query.ts b/clients/client-cloudsearch/src/protocols/Aws_query.ts index a0bd9a9922b33..3f72b13841c0d 100644 --- a/clients/client-cloudsearch/src/protocols/Aws_query.ts +++ b/clients/client-cloudsearch/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, serializeFloat as __serializeFloat, @@ -22,7 +22,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { BuildSuggestersCommandInput, BuildSuggestersCommandOutput } from "../commands/BuildSuggestersCommand"; import { CreateDomainCommandInput, CreateDomainCommandOutput } from "../commands/CreateDomainCommand"; @@ -3572,41 +3571,6 @@ const _V = "Version"; const _e = "entry"; const _m = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-cloudtrail-data/src/protocols/Aws_restJson1.ts b/clients/client-cloudtrail-data/src/protocols/Aws_restJson1.ts index 1a8c36b8ea8ae..5e81c423d4250 100644 --- a/clients/client-cloudtrail-data/src/protocols/Aws_restJson1.ts +++ b/clients/client-cloudtrail-data/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -265,54 +266,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _cA = "channelArn"; const _eI = "externalId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudtrail/src/protocols/Aws_json1_1.ts b/clients/client-cloudtrail/src/protocols/Aws_json1_1.ts index f7f15dd8ff8ff..c941bbd0d1ec7 100644 --- a/clients/client-cloudtrail/src/protocols/Aws_json1_1.ts +++ b/clients/client-cloudtrail/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4509,54 +4510,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CloudTrail_20131101.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudwatch-events/src/protocols/Aws_json1_1.ts b/clients/client-cloudwatch-events/src/protocols/Aws_json1_1.ts index dd7842bb0f7d7..38d037a3d7ffb 100644 --- a/clients/client-cloudwatch-events/src/protocols/Aws_json1_1.ts +++ b/clients/client-cloudwatch-events/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3092,54 +3093,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSEvents.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudwatch-logs/src/protocols/Aws_json1_1.ts b/clients/client-cloudwatch-logs/src/protocols/Aws_json1_1.ts index d49685b78599f..2dd3a5bf07138 100644 --- a/clients/client-cloudwatch-logs/src/protocols/Aws_json1_1.ts +++ b/clients/client-cloudwatch-logs/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -3703,54 +3704,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Logs_20140328.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cloudwatch/package.json b/clients/client-cloudwatch/package.json index f1fb0f4024385..b4eae5c0872f3 100644 --- a/clients/client-cloudwatch/package.json +++ b/clients/client-cloudwatch/package.json @@ -59,7 +59,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-cloudwatch/src/protocols/Aws_query.ts b/clients/client-cloudwatch/src/protocols/Aws_query.ts index f0c2d85281c39..6d514f6d85456 100644 --- a/clients/client-cloudwatch/src/protocols/Aws_query.ts +++ b/clients/client-cloudwatch/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, serializeFloat as __serializeFloat, @@ -22,7 +22,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { DeleteAlarmsCommandInput, DeleteAlarmsCommandOutput } from "../commands/DeleteAlarmsCommand"; import { @@ -5718,41 +5717,6 @@ const _e = "entry"; const _m = "member"; const _me = "message"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-codeartifact/src/protocols/Aws_restJson1.ts b/clients/client-codeartifact/src/protocols/Aws_restJson1.ts index 638b32810607b..c10ef41511ab9 100644 --- a/clients/client-codeartifact/src/protocols/Aws_restJson1.ts +++ b/clients/client-codeartifact/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2337,54 +2338,3 @@ const _xa = "x-assetname"; const _xacs = "x-amz-content-sha256"; const _xp = "x-packageversion"; const _xp_ = "x-packageversionrevision"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codebuild/src/protocols/Aws_json1_1.ts b/clients/client-codebuild/src/protocols/Aws_json1_1.ts index 325ea168bf26b..9a4d7cdc0ca87 100644 --- a/clients/client-codebuild/src/protocols/Aws_json1_1.ts +++ b/clients/client-codebuild/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3199,54 +3200,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CodeBuild_20161006.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codecatalyst/src/protocols/Aws_restJson1.ts b/clients/client-codecatalyst/src/protocols/Aws_restJson1.ts index ed25407b761cb..ec090b1a1a224 100644 --- a/clients/client-codecatalyst/src/protocols/Aws_restJson1.ts +++ b/clients/client-codecatalyst/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2350,54 +2351,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _uN = "userName"; const _wI = "workflowId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codecommit/src/protocols/Aws_json1_1.ts b/clients/client-codecommit/src/protocols/Aws_json1_1.ts index 99ea087ef1a95..7a698e0ac3fe7 100644 --- a/clients/client-codecommit/src/protocols/Aws_json1_1.ts +++ b/clients/client-codecommit/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -8329,54 +8330,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CodeCommit_20150413.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codedeploy/src/protocols/Aws_json1_1.ts b/clients/client-codedeploy/src/protocols/Aws_json1_1.ts index d0dfaea125dd2..97fedc97516a2 100644 --- a/clients/client-codedeploy/src/protocols/Aws_json1_1.ts +++ b/clients/client-codedeploy/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -5230,54 +5231,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CodeDeploy_20141006.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codeguru-reviewer/src/protocols/Aws_restJson1.ts b/clients/client-codeguru-reviewer/src/protocols/Aws_restJson1.ts index 78d06492c24ec..fd4aebff76354 100644 --- a/clients/client-codeguru-reviewer/src/protocols/Aws_restJson1.ts +++ b/clients/client-codeguru-reviewer/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1083,54 +1084,3 @@ const _TK = "TagKeys"; const _UI = "UserId"; const _UIs = "UserIds"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codeguru-security/src/protocols/Aws_restJson1.ts b/clients/client-codeguru-security/src/protocols/Aws_restJson1.ts index c857684f1b01b..b522ee8f0966e 100644 --- a/clients/client-codeguru-security/src/protocols/Aws_restJson1.ts +++ b/clients/client-codeguru-security/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -996,54 +1001,3 @@ const _rI = "runId"; const _s = "status"; const _sD = "startDate"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codeguruprofiler/src/protocols/Aws_restJson1.ts b/clients/client-codeguruprofiler/src/protocols/Aws_restJson1.ts index 4e5768a5b9cc8..c8eceee085bb8 100644 --- a/clients/client-codeguruprofiler/src/protocols/Aws_restJson1.ts +++ b/clients/client-codeguruprofiler/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1605,54 +1606,3 @@ const _rI = "revisionId"; const _sT = "startTime"; const _tK = "tagKeys"; const _tR = "targetResolution"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codepipeline/src/protocols/Aws_json1_1.ts b/clients/client-codepipeline/src/protocols/Aws_json1_1.ts index 74891d31fe865..5104bf66c6c06 100644 --- a/clients/client-codepipeline/src/protocols/Aws_json1_1.ts +++ b/clients/client-codepipeline/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3209,54 +3210,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CodePipeline_20150709.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codestar-connections/src/protocols/Aws_json1_0.ts b/clients/client-codestar-connections/src/protocols/Aws_json1_0.ts index 52842a6fe5b5d..47ea4a41faf66 100644 --- a/clients/client-codestar-connections/src/protocols/Aws_json1_0.ts +++ b/clients/client-codestar-connections/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1752,54 +1753,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CodeStar_connections_20191201.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codestar-notifications/src/protocols/Aws_restJson1.ts b/clients/client-codestar-notifications/src/protocols/Aws_restJson1.ts index 0d02bf60b4ff8..2c2756557a60e 100644 --- a/clients/client-codestar-notifications/src/protocols/Aws_restJson1.ts +++ b/clients/client-codestar-notifications/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -910,54 +911,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-codestar/src/protocols/Aws_json1_1.ts b/clients/client-codestar/src/protocols/Aws_json1_1.ts index 1c3555f12094f..de76417e96d78 100644 --- a/clients/client-codestar/src/protocols/Aws_json1_1.ts +++ b/clients/client-codestar/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1186,54 +1187,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CodeStar_20170419.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cognito-identity-provider/src/protocols/Aws_json1_1.ts b/clients/client-cognito-identity-provider/src/protocols/Aws_json1_1.ts index 8ae7b8e98ef23..f6ab26333a8a1 100644 --- a/clients/client-cognito-identity-provider/src/protocols/Aws_json1_1.ts +++ b/clients/client-cognito-identity-provider/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -6133,54 +6134,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSCognitoIdentityProviderService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cognito-identity/src/protocols/Aws_json1_1.ts b/clients/client-cognito-identity/src/protocols/Aws_json1_1.ts index 4ba8430b494a1..0aea4f3ca09d6 100644 --- a/clients/client-cognito-identity/src/protocols/Aws_json1_1.ts +++ b/clients/client-cognito-identity/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1361,54 +1362,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSCognitoIdentityService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cognito-sync/src/protocols/Aws_restJson1.ts b/clients/client-cognito-sync/src/protocols/Aws_restJson1.ts index c93bbe06491a0..f221cf4360a25 100644 --- a/clients/client-cognito-sync/src/protocols/Aws_restJson1.ts +++ b/clients/client-cognito-sync/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1269,54 +1270,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _sST = "syncSessionToken"; const _xacc = "x-amz-client-context"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-comprehend/src/protocols/Aws_json1_1.ts b/clients/client-comprehend/src/protocols/Aws_json1_1.ts index a106bba5a0a55..c4b91a708242e 100644 --- a/clients/client-comprehend/src/protocols/Aws_json1_1.ts +++ b/clients/client-comprehend/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -6563,54 +6564,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Comprehend_20171127.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-comprehendmedical/src/protocols/Aws_json1_1.ts b/clients/client-comprehendmedical/src/protocols/Aws_json1_1.ts index 1e26e1d6726e1..1ad412305e4fb 100644 --- a/clients/client-comprehendmedical/src/protocols/Aws_json1_1.ts +++ b/clients/client-comprehendmedical/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2122,54 +2123,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `ComprehendMedical_20181030.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-compute-optimizer/src/protocols/Aws_json1_0.ts b/clients/client-compute-optimizer/src/protocols/Aws_json1_0.ts index 627bae7a2a491..be91344aa9e80 100644 --- a/clients/client-compute-optimizer/src/protocols/Aws_json1_0.ts +++ b/clients/client-compute-optimizer/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2614,54 +2615,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `ComputeOptimizerService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-config-service/src/protocols/Aws_json1_1.ts b/clients/client-config-service/src/protocols/Aws_json1_1.ts index f6b21f80effb6..b0ccd49dbf9e2 100644 --- a/clients/client-config-service/src/protocols/Aws_json1_1.ts +++ b/clients/client-config-service/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -6823,54 +6824,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `StarlingDoveService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-connect-contact-lens/src/protocols/Aws_restJson1.ts b/clients/client-connect-contact-lens/src/protocols/Aws_restJson1.ts index b4c5f8da01191..7a2f8541c83d4 100644 --- a/clients/client-connect-contact-lens/src/protocols/Aws_restJson1.ts +++ b/clients/client-connect-contact-lens/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -253,54 +254,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-connect/src/protocols/Aws_restJson1.ts b/clients/client-connect/src/protocols/Aws_restJson1.ts index 1757ecefc71c6..ce1a60d005239 100644 --- a/clients/client-connect/src/protocols/Aws_restJson1.ts +++ b/clients/client-connect/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -14819,54 +14824,3 @@ const _st = "status"; const _t = "type"; const _tK = "tagKeys"; const _v = "version"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-connectcampaigns/src/protocols/Aws_restJson1.ts b/clients/client-connectcampaigns/src/protocols/Aws_restJson1.ts index dd0d0fc19003b..b31ec63ea5859 100644 --- a/clients/client-connectcampaigns/src/protocols/Aws_restJson1.ts +++ b/clients/client-connectcampaigns/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1382,54 +1387,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _tK = "tagKeys"; const _xAET = "xAmzErrorType"; const _xae = "x-amzn-errortype"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-connectcases/src/protocols/Aws_restJson1.ts b/clients/client-connectcases/src/protocols/Aws_restJson1.ts index ab84c0d90dd05..4950c4a8d288b 100644 --- a/clients/client-connectcases/src/protocols/Aws_restJson1.ts +++ b/clients/client-connectcases/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2145,54 +2150,3 @@ const _ra = "retry-after"; const _s = "status"; const _tK = "tagKeys"; const _v = "values"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-connectparticipant/src/protocols/Aws_restJson1.ts b/clients/client-connectparticipant/src/protocols/Aws_restJson1.ts index 5b6a570320340..e6f70dadfce4a 100644 --- a/clients/client-connectparticipant/src/protocols/Aws_restJson1.ts +++ b/clients/client-connectparticipant/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -689,54 +690,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _CT = "ConnectionToken"; const _PT = "ParticipantToken"; const _xab = "x-amz-bearer"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-controltower/src/protocols/Aws_restJson1.ts b/clients/client-controltower/src/protocols/Aws_restJson1.ts index e563d29e79332..7df34c0c86eb3 100644 --- a/clients/client-controltower/src/protocols/Aws_restJson1.ts +++ b/clients/client-controltower/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1641,54 +1642,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cost-and-usage-report-service/src/protocols/Aws_json1_1.ts b/clients/client-cost-and-usage-report-service/src/protocols/Aws_json1_1.ts index fb97cd0ded1a0..196fcd1069417 100644 --- a/clients/client-cost-and-usage-report-service/src/protocols/Aws_json1_1.ts +++ b/clients/client-cost-and-usage-report-service/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -508,54 +509,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSOrigamiServiceGatewayService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cost-explorer/src/protocols/Aws_json1_1.ts b/clients/client-cost-explorer/src/protocols/Aws_json1_1.ts index 2acf67157f34a..11768585eabb8 100644 --- a/clients/client-cost-explorer/src/protocols/Aws_json1_1.ts +++ b/clients/client-cost-explorer/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2870,54 +2871,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSInsightsIndexService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-cost-optimization-hub/src/protocols/Aws_json1_0.ts b/clients/client-cost-optimization-hub/src/protocols/Aws_json1_0.ts index 044d43939fece..2950834b7d854 100644 --- a/clients/client-cost-optimization-hub/src/protocols/Aws_json1_0.ts +++ b/clients/client-cost-optimization-hub/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1090,54 +1095,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `CostOptimizationHubService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-customer-profiles/src/protocols/Aws_restJson1.ts b/clients/client-customer-profiles/src/protocols/Aws_restJson1.ts index 5f150b2bc72f2..3e55e19e76b7b 100644 --- a/clients/client-customer-profiles/src/protocols/Aws_restJson1.ts +++ b/clients/client-customer-profiles/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3415,54 +3416,3 @@ const _ih = "include-hidden"; const _mr = "max-results"; const _nt = "next-token"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-data-pipeline/src/protocols/Aws_json1_1.ts b/clients/client-data-pipeline/src/protocols/Aws_json1_1.ts index a35215da1ebf3..df5adf8964b45 100644 --- a/clients/client-data-pipeline/src/protocols/Aws_json1_1.ts +++ b/clients/client-data-pipeline/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1039,54 +1040,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `DataPipeline.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-database-migration-service/src/protocols/Aws_json1_1.ts b/clients/client-database-migration-service/src/protocols/Aws_json1_1.ts index 2f800699240cd..7d5c7a032e7c6 100644 --- a/clients/client-database-migration-service/src/protocols/Aws_json1_1.ts +++ b/clients/client-database-migration-service/src/protocols/Aws_json1_1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -6639,54 +6644,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonDMSv20160101.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-databrew/src/protocols/Aws_restJson1.ts b/clients/client-databrew/src/protocols/Aws_restJson1.ts index 024b9eba5aea4..9030ed0a94fc0 100644 --- a/clients/client-databrew/src/protocols/Aws_restJson1.ts +++ b/clients/client-databrew/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2850,54 +2851,3 @@ const _pN = "projectName"; const _rV = "recipeVersion"; const _tA = "targetArn"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-dataexchange/src/protocols/Aws_restJson1.ts b/clients/client-dataexchange/src/protocols/Aws_restJson1.ts index 2ce9be748f16a..cb7c2881ddc7d 100644 --- a/clients/client-dataexchange/src/protocols/Aws_restJson1.ts +++ b/clients/client-dataexchange/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -2198,54 +2199,3 @@ const _xaddsi = "x-amzn-dataexchange-data-set-id"; const _xadhm = "x-amzn-dataexchange-http-method"; const _xadp = "x-amzn-dataexchange-path"; const _xadri = "x-amzn-dataexchange-revision-id"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-datasync/src/protocols/Aws_json1_1.ts b/clients/client-datasync/src/protocols/Aws_json1_1.ts index d4c3fb6b80d91..b52884af05df4 100644 --- a/clients/client-datasync/src/protocols/Aws_json1_1.ts +++ b/clients/client-datasync/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -3489,54 +3490,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `FmrsService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-datazone/src/protocols/Aws_restJson1.ts b/clients/client-datazone/src/protocols/Aws_restJson1.ts index f5477b168649a..3317c3cb95b82 100644 --- a/clients/client-datazone/src/protocols/Aws_restJson1.ts +++ b/clients/client-datazone/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -6553,54 +6558,3 @@ const _t = "type"; const _tK = "tagKeys"; const _tS = "taskStatus"; const _uI = "userIdentifier"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-dax/src/protocols/Aws_json1_1.ts b/clients/client-dax/src/protocols/Aws_json1_1.ts index cf082e511d67e..216af885c8fd0 100644 --- a/clients/client-dax/src/protocols/Aws_json1_1.ts +++ b/clients/client-dax/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1751,54 +1752,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonDAXV3.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-detective/src/protocols/Aws_restJson1.ts b/clients/client-detective/src/protocols/Aws_restJson1.ts index 96415979094ae..099220cecdff7 100644 --- a/clients/client-detective/src/protocols/Aws_restJson1.ts +++ b/clients/client-detective/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1883,54 +1884,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-device-farm/src/protocols/Aws_json1_1.ts b/clients/client-device-farm/src/protocols/Aws_json1_1.ts index 4c1d2de2a933b..f543236c54a49 100644 --- a/clients/client-device-farm/src/protocols/Aws_json1_1.ts +++ b/clients/client-device-farm/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4672,54 +4673,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `DeviceFarm_20150623.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-devops-guru/src/protocols/Aws_restJson1.ts b/clients/client-devops-guru/src/protocols/Aws_restJson1.ts index f1e1fc483ee45..aa21d25404d2b 100644 --- a/clients/client-devops-guru/src/protocols/Aws_restJson1.ts +++ b/clients/client-devops-guru/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2712,54 +2713,3 @@ const _AI = "AccountId"; const _NT = "NextToken"; const _RAS = "RetryAfterSeconds"; const _ra = "retry-after"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-direct-connect/src/protocols/Aws_json1_1.ts b/clients/client-direct-connect/src/protocols/Aws_json1_1.ts index e7e80b2c3c43f..6c5df47fbb046 100644 --- a/clients/client-direct-connect/src/protocols/Aws_json1_1.ts +++ b/clients/client-direct-connect/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3043,54 +3044,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `OvertureService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-directory-service/src/protocols/Aws_json1_1.ts b/clients/client-directory-service/src/protocols/Aws_json1_1.ts index 55904155da148..d20ce27284ae9 100644 --- a/clients/client-directory-service/src/protocols/Aws_json1_1.ts +++ b/clients/client-directory-service/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4322,54 +4323,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `DirectoryService_20150416.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-dlm/src/protocols/Aws_restJson1.ts b/clients/client-dlm/src/protocols/Aws_restJson1.ts index 72313cb495d35..162335dbd8055 100644 --- a/clients/client-dlm/src/protocols/Aws_restJson1.ts +++ b/clients/client-dlm/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -771,54 +772,3 @@ const _s = "state"; const _tK = "tagKeys"; const _tT = "targetTags"; const _tTA = "tagsToAdd"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-docdb-elastic/src/protocols/Aws_restJson1.ts b/clients/client-docdb-elastic/src/protocols/Aws_restJson1.ts index 9eedc2675fd23..086ea65f2b406 100644 --- a/clients/client-docdb-elastic/src/protocols/Aws_restJson1.ts +++ b/clients/client-docdb-elastic/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -977,54 +978,3 @@ const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _sT = "snapshotType"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-docdb/package.json b/clients/client-docdb/package.json index bdcebc2ca00fc..587a9570ba552 100644 --- a/clients/client-docdb/package.json +++ b/clients/client-docdb/package.json @@ -59,7 +59,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-docdb/src/protocols/Aws_query.ts b/clients/client-docdb/src/protocols/Aws_query.ts index 1c0e5d937c2b2..921c8621aa26f 100644 --- a/clients/client-docdb/src/protocols/Aws_query.ts +++ b/clients/client-docdb/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseInt32 as __strictParseInt32, @@ -19,7 +19,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddSourceIdentifierToSubscriptionCommandInput, @@ -8264,41 +8263,6 @@ const _Vp = "Vpc"; const _m = "message"; const _me = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-drs/src/protocols/Aws_restJson1.ts b/clients/client-drs/src/protocols/Aws_restJson1.ts index f49395e3bdf1d..d9cfb2ed078e2 100644 --- a/clients/client-drs/src/protocols/Aws_restJson1.ts +++ b/clients/client-drs/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3059,54 +3060,3 @@ const _nT = "nextToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-dynamodb-streams/src/protocols/Aws_json1_0.ts b/clients/client-dynamodb-streams/src/protocols/Aws_json1_0.ts index 2639e39035d53..ed40ca2e4f526 100644 --- a/clients/client-dynamodb-streams/src/protocols/Aws_json1_0.ts +++ b/clients/client-dynamodb-streams/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -550,54 +555,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `DynamoDBStreams_20120810.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-dynamodb/src/protocols/Aws_json1_0.ts b/clients/client-dynamodb/src/protocols/Aws_json1_0.ts index 3e11586e84c1c..2d46589c9b497 100644 --- a/clients/client-dynamodb/src/protocols/Aws_json1_0.ts +++ b/clients/client-dynamodb/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -5487,54 +5492,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `DynamoDB_20120810.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ebs/src/protocols/Aws_restJson1.ts b/clients/client-ebs/src/protocols/Aws_restJson1.ts index 89b93f70c0276..156778ef6c190 100644 --- a/clients/client-ebs/src/protocols/Aws_restJson1.ts +++ b/clients/client-ebs/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -590,54 +591,3 @@ const _xaca = "x-amz-checksum-algorithm"; const _xacam = "x-amz-checksum-aggregation-method"; const _xadl = "x-amz-data-length"; const _xap = "x-amz-progress"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ec2-instance-connect/src/protocols/Aws_json1_1.ts b/clients/client-ec2-instance-connect/src/protocols/Aws_json1_1.ts index 7b6c622705fc1..24c4ed418095d 100644 --- a/clients/client-ec2-instance-connect/src/protocols/Aws_json1_1.ts +++ b/clients/client-ec2-instance-connect/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -394,54 +395,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSEC2InstanceConnectService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ec2/package.json b/clients/client-ec2/package.json index c2f9f8c5b1d03..7a2f3b0fc0eae 100644 --- a/clients/client-ec2/package.json +++ b/clients/client-ec2/package.json @@ -59,7 +59,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0", "uuid": "^9.0.1" }, diff --git a/clients/client-ec2/src/protocols/Aws_ec2.ts b/clients/client-ec2/src/protocols/Aws_ec2.ts index c78496c605b8e..919645000a61e 100644 --- a/clients/client-ec2/src/protocols/Aws_ec2.ts +++ b/clients/client-ec2/src/protocols/Aws_ec2.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -6,7 +7,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, serializeFloat as __serializeFloat, @@ -21,7 +21,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { v4 as generateIdempotencyToken } from "uuid"; import { @@ -87187,41 +87186,6 @@ const _zN = "zoneName"; const _zS = "zoneState"; const _zT = "zoneType"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-ecr-public/src/protocols/Aws_json1_1.ts b/clients/client-ecr-public/src/protocols/Aws_json1_1.ts index 85cc1d050a8b1..b285e74b8f2a8 100644 --- a/clients/client-ecr-public/src/protocols/Aws_json1_1.ts +++ b/clients/client-ecr-public/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1810,54 +1811,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `SpencerFrontendService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ecr/src/protocols/Aws_json1_1.ts b/clients/client-ecr/src/protocols/Aws_json1_1.ts index 6369422944b8c..7f961e83d9964 100644 --- a/clients/client-ecr/src/protocols/Aws_json1_1.ts +++ b/clients/client-ecr/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3331,54 +3332,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonEC2ContainerRegistry_V20150921.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ecs/src/protocols/Aws_json1_1.ts b/clients/client-ecs/src/protocols/Aws_json1_1.ts index d246a218cedb2..961e1f069bd0c 100644 --- a/clients/client-ecs/src/protocols/Aws_json1_1.ts +++ b/clients/client-ecs/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4316,54 +4317,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonEC2ContainerServiceV20141113.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-efs/src/protocols/Aws_restJson1.ts b/clients/client-efs/src/protocols/Aws_restJson1.ts index dd1fe820da0c8..ee5b4b166d38e 100644 --- a/clients/client-efs/src/protocols/Aws_restJson1.ts +++ b/clients/client-efs/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2427,54 +2428,3 @@ const _MTI = "MountTargetId"; const _NT = "NextToken"; const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-eks-auth/src/protocols/Aws_restJson1.ts b/clients/client-eks-auth/src/protocols/Aws_restJson1.ts index 43ae1e8a75fd3..3faf6baf9f3d1 100644 --- a/clients/client-eks-auth/src/protocols/Aws_restJson1.ts +++ b/clients/client-eks-auth/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -348,54 +349,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-eks/src/protocols/Aws_restJson1.ts b/clients/client-eks/src/protocols/Aws_restJson1.ts index 0a7c0d5299f2a..6ec45d3083b86 100644 --- a/clients/client-eks/src/protocols/Aws_restJson1.ts +++ b/clients/client-eks/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3538,54 +3539,3 @@ const _pu = "publishers"; const _sA = "serviceAccount"; const _t = "types"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-elastic-beanstalk/package.json b/clients/client-elastic-beanstalk/package.json index a7c6191b757ea..ea386c7a51c81 100644 --- a/clients/client-elastic-beanstalk/package.json +++ b/clients/client-elastic-beanstalk/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-elastic-beanstalk/src/protocols/Aws_query.ts b/clients/client-elastic-beanstalk/src/protocols/Aws_query.ts index 36766df601989..669cbbf306452 100644 --- a/clients/client-elastic-beanstalk/src/protocols/Aws_query.ts +++ b/clients/client-elastic-beanstalk/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseFloat as __strictParseFloat, @@ -21,7 +21,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AbortEnvironmentUpdateCommandInput, @@ -6687,41 +6686,6 @@ const _WST = "WindowStartTime"; const _m = "member"; const _me = "message"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-elastic-inference/src/protocols/Aws_restJson1.ts b/clients/client-elastic-inference/src/protocols/Aws_restJson1.ts index 90316aeb78438..3538a0917cb22 100644 --- a/clients/client-elastic-inference/src/protocols/Aws_restJson1.ts +++ b/clients/client-elastic-inference/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -428,54 +429,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-elastic-load-balancing-v2/package.json b/clients/client-elastic-load-balancing-v2/package.json index 4a963d6ca7d3c..d183695e10957 100644 --- a/clients/client-elastic-load-balancing-v2/package.json +++ b/clients/client-elastic-load-balancing-v2/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-elastic-load-balancing-v2/src/protocols/Aws_query.ts b/clients/client-elastic-load-balancing-v2/src/protocols/Aws_query.ts index cb8352fd0e3f3..957bb07d40d70 100644 --- a/clients/client-elastic-load-balancing-v2/src/protocols/Aws_query.ts +++ b/clients/client-elastic-load-balancing-v2/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseInt32 as __strictParseInt32, @@ -20,7 +20,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddListenerCertificatesCommandInput, @@ -7782,41 +7781,6 @@ const _ZN = "ZoneName"; const _e = "entry"; const _m = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-elastic-load-balancing/package.json b/clients/client-elastic-load-balancing/package.json index 21827b80a6869..e0a06ded3724d 100644 --- a/clients/client-elastic-load-balancing/package.json +++ b/clients/client-elastic-load-balancing/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-elastic-load-balancing/src/protocols/Aws_query.ts b/clients/client-elastic-load-balancing/src/protocols/Aws_query.ts index 385c24c53f110..04fe42cf215c6 100644 --- a/clients/client-elastic-load-balancing/src/protocols/Aws_query.ts +++ b/clients/client-elastic-load-balancing/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseInt32 as __strictParseInt32, @@ -20,7 +20,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddTagsCommandInput, AddTagsCommandOutput } from "../commands/AddTagsCommand"; import { @@ -4287,41 +4286,6 @@ const _VPCI = "VPCId"; const _Va = "Value"; const _m = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-elastic-transcoder/src/protocols/Aws_restJson1.ts b/clients/client-elastic-transcoder/src/protocols/Aws_restJson1.ts index 8b1f3ef8b41a5..eaac3072e8f1f 100644 --- a/clients/client-elastic-transcoder/src/protocols/Aws_restJson1.ts +++ b/clients/client-elastic-transcoder/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1165,54 +1166,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _A = "Ascending"; const _PT = "PageToken"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-elasticache/package.json b/clients/client-elasticache/package.json index 4687b05d6775a..1b31622f657ff 100644 --- a/clients/client-elasticache/package.json +++ b/clients/client-elasticache/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-elasticache/src/protocols/Aws_query.ts b/clients/client-elasticache/src/protocols/Aws_query.ts index 066540a7a610c..30bc242585dc6 100644 --- a/clients/client-elasticache/src/protocols/Aws_query.ts +++ b/clients/client-elasticache/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseFloat as __strictParseFloat, @@ -20,7 +20,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddTagsToResourceCommandInput, AddTagsToResourceCommandOutput } from "../commands/AddTagsToResourceCommand"; import { @@ -12615,41 +12614,6 @@ const _Val = "Value"; const _m = "member"; const _me = "message"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-elasticsearch-service/src/protocols/Aws_restJson1.ts b/clients/client-elasticsearch-service/src/protocols/Aws_restJson1.ts index dcec2889ac526..2c8e45d348bb6 100644 --- a/clients/client-elasticsearch-service/src/protocols/Aws_restJson1.ts +++ b/clients/client-elasticsearch-service/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3573,54 +3574,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _oI = "offeringId"; const _rI = "reservationId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-emr-containers/src/protocols/Aws_restJson1.ts b/clients/client-emr-containers/src/protocols/Aws_restJson1.ts index 7f2ca6a309c80..292a5235f8e05 100644 --- a/clients/client-emr-containers/src/protocols/Aws_restJson1.ts +++ b/clients/client-emr-containers/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1438,54 +1443,3 @@ const _nT = "nextToken"; const _s = "states"; const _t = "types"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-emr-serverless/src/protocols/Aws_restJson1.ts b/clients/client-emr-serverless/src/protocols/Aws_restJson1.ts index e01f39c7311ca..46fa2a7e673ad 100644 --- a/clients/client-emr-serverless/src/protocols/Aws_restJson1.ts +++ b/clients/client-emr-serverless/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1155,54 +1160,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _s = "states"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-emr/src/protocols/Aws_json1_1.ts b/clients/client-emr/src/protocols/Aws_json1_1.ts index da10c90f2f100..7c8c974ad1ec4 100644 --- a/clients/client-emr/src/protocols/Aws_json1_1.ts +++ b/clients/client-emr/src/protocols/Aws_json1_1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4079,54 +4084,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `ElasticMapReduce.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-entityresolution/src/protocols/Aws_restJson1.ts b/clients/client-entityresolution/src/protocols/Aws_restJson1.ts index fbdf9a792211f..8e6f5a9eca727 100644 --- a/clients/client-entityresolution/src/protocols/Aws_restJson1.ts +++ b/clients/client-entityresolution/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1780,54 +1785,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _pN = "providerName"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-eventbridge/src/protocols/Aws_json1_1.ts b/clients/client-eventbridge/src/protocols/Aws_json1_1.ts index ff2887c11038a..b564b55daa44c 100644 --- a/clients/client-eventbridge/src/protocols/Aws_json1_1.ts +++ b/clients/client-eventbridge/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3394,54 +3395,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSEvents.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-evidently/src/protocols/Aws_restJson1.ts b/clients/client-evidently/src/protocols/Aws_restJson1.ts index cf7f24101fdad..d8de16ad8184e 100644 --- a/clients/client-evidently/src/protocols/Aws_restJson1.ts +++ b/clients/client-evidently/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -2731,54 +2736,3 @@ const _nT = "nextToken"; const _s = "status"; const _t = "type"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-finspace-data/src/protocols/Aws_restJson1.ts b/clients/client-finspace-data/src/protocols/Aws_restJson1.ts index ebfa1766fea54..92024ea0801d3 100644 --- a/clients/client-finspace-data/src/protocols/Aws_restJson1.ts +++ b/clients/client-finspace-data/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1777,54 +1778,3 @@ const _dIM = "durationInMinutes"; const _eI = "environmentId"; const _mR = "maxResults"; const _nT = "nextToken"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-finspace/src/protocols/Aws_restJson1.ts b/clients/client-finspace/src/protocols/Aws_restJson1.ts index aed8e4ed1fc3e..34d2a4010ef37 100644 --- a/clients/client-finspace/src/protocols/Aws_restJson1.ts +++ b/clients/client-finspace/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3235,54 +3236,3 @@ const _nT = "nextToken"; const _tK = "tagKeys"; const _uA = "userArn"; const _vT = "volumeType"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-firehose/src/protocols/Aws_json1_1.ts b/clients/client-firehose/src/protocols/Aws_json1_1.ts index 224ea066e7a02..0565506a8b45d 100644 --- a/clients/client-firehose/src/protocols/Aws_json1_1.ts +++ b/clients/client-firehose/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1421,54 +1422,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Firehose_20150804.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-fis/src/protocols/Aws_restJson1.ts b/clients/client-fis/src/protocols/Aws_restJson1.ts index 8b0ea2a5a2cbd..f0e7c951d740e 100644 --- a/clients/client-fis/src/protocols/Aws_restJson1.ts +++ b/clients/client-fis/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1519,54 +1520,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; const _tN = "targetName"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-fms/src/protocols/Aws_json1_1.ts b/clients/client-fms/src/protocols/Aws_json1_1.ts index 09a503956a335..6f2ae2a164c0e 100644 --- a/clients/client-fms/src/protocols/Aws_json1_1.ts +++ b/clients/client-fms/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2474,54 +2475,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSFMS_20180101.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-forecast/src/protocols/Aws_json1_1.ts b/clients/client-forecast/src/protocols/Aws_json1_1.ts index 64f6909b84ae8..52046665102c8 100644 --- a/clients/client-forecast/src/protocols/Aws_json1_1.ts +++ b/clients/client-forecast/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4222,54 +4223,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonForecast.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-forecastquery/src/protocols/Aws_json1_1.ts b/clients/client-forecastquery/src/protocols/Aws_json1_1.ts index abf81bb5a39cb..5521a3bf48a29 100644 --- a/clients/client-forecastquery/src/protocols/Aws_json1_1.ts +++ b/clients/client-forecastquery/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -338,54 +339,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonForecastRuntime.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-frauddetector/src/protocols/Aws_json1_1.ts b/clients/client-frauddetector/src/protocols/Aws_json1_1.ts index 16072e2b21359..b971070d7f46e 100644 --- a/clients/client-frauddetector/src/protocols/Aws_json1_1.ts +++ b/clients/client-frauddetector/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3928,54 +3929,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSHawksNestServiceFacade.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-freetier/src/protocols/Aws_json1_0.ts b/clients/client-freetier/src/protocols/Aws_json1_0.ts index 13b2467c416c4..38e4ee682d8b3 100644 --- a/clients/client-freetier/src/protocols/Aws_json1_0.ts +++ b/clients/client-freetier/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -263,54 +264,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSFreeTierService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-fsx/src/protocols/Aws_json1_1.ts b/clients/client-fsx/src/protocols/Aws_json1_1.ts index 5b972ad829866..593331f859892 100644 --- a/clients/client-fsx/src/protocols/Aws_json1_1.ts +++ b/clients/client-fsx/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4055,54 +4056,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSSimbaAPIService_v20180301.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-gamelift/src/protocols/Aws_json1_1.ts b/clients/client-gamelift/src/protocols/Aws_json1_1.ts index de2f3b0b0e52f..9bcffe401f1ab 100644 --- a/clients/client-gamelift/src/protocols/Aws_json1_1.ts +++ b/clients/client-gamelift/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -6219,54 +6220,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `GameLift.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-glacier/src/protocols/Aws_restJson1.ts b/clients/client-glacier/src/protocols/Aws_restJson1.ts index d65706e1ed99d..606724f788800 100644 --- a/clients/client-glacier/src/protocols/Aws_restJson1.ts +++ b/clients/client-glacier/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1844,54 +1845,3 @@ const _xali = "x-amz-lock-id"; const _xamui = "x-amz-multipart-upload-id"; const _xaps = "x-amz-part-size"; const _xasth = "x-amz-sha256-tree-hash"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-global-accelerator/src/protocols/Aws_json1_1.ts b/clients/client-global-accelerator/src/protocols/Aws_json1_1.ts index d29150911a7d9..54853a385ec4e 100644 --- a/clients/client-global-accelerator/src/protocols/Aws_json1_1.ts +++ b/clients/client-global-accelerator/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3398,54 +3399,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `GlobalAccelerator_V20180706.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-glue/src/protocols/Aws_json1_1.ts b/clients/client-glue/src/protocols/Aws_json1_1.ts index ba58c84e57e51..726ac26b54533 100644 --- a/clients/client-glue/src/protocols/Aws_json1_1.ts +++ b/clients/client-glue/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -14494,54 +14495,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSGlue.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-grafana/src/protocols/Aws_restJson1.ts b/clients/client-grafana/src/protocols/Aws_restJson1.ts index 8e3eaf76b3fbc..5418f209a4a6f 100644 --- a/clients/client-grafana/src/protocols/Aws_restJson1.ts +++ b/clients/client-grafana/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1280,54 +1281,3 @@ const _uI = "userId"; const _uT = "userType"; const _wI = "workspaceId"; const _wi = "workspace-id"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-greengrass/src/protocols/Aws_restJson1.ts b/clients/client-greengrass/src/protocols/Aws_restJson1.ts index c581fc144bf10..248b9eac08e05 100644 --- a/clients/client-greengrass/src/protocols/Aws_restJson1.ts +++ b/clients/client-greengrass/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4633,54 +4634,3 @@ const _NT = "NextToken"; const _TK = "TagKeys"; const _tK = "tagKeys"; const _xact = "x-amzn-client-token"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-greengrassv2/src/protocols/Aws_restJson1.ts b/clients/client-greengrassv2/src/protocols/Aws_restJson1.ts index a6378bbc53452..32ccc4eea25cf 100644 --- a/clients/client-greengrassv2/src/protocols/Aws_restJson1.ts +++ b/clients/client-greengrassv2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2189,54 +2190,3 @@ const _tA = "targetArn"; const _tF = "topologyFilter"; const _tGA = "thingGroupArn"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-groundstation/src/protocols/Aws_restJson1.ts b/clients/client-groundstation/src/protocols/Aws_restJson1.ts index 621c61c540510..8d3739c002e51 100644 --- a/clients/client-groundstation/src/protocols/Aws_restJson1.ts +++ b/clients/client-groundstation/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2275,54 +2280,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _sI = "satelliteId"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-guardduty/src/protocols/Aws_restJson1.ts b/clients/client-guardduty/src/protocols/Aws_restJson1.ts index 563981e86cf09..7215bb1450d5f 100644 --- a/clients/client-guardduty/src/protocols/Aws_restJson1.ts +++ b/clients/client-guardduty/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -6540,54 +6541,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _oA = "onlyAssociated"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-health/src/protocols/Aws_json1_1.ts b/clients/client-health/src/protocols/Aws_json1_1.ts index bd8f0b8b71f1a..0e1da5c89dd1a 100644 --- a/clients/client-health/src/protocols/Aws_json1_1.ts +++ b/clients/client-health/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1137,54 +1138,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSHealth_20160804.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-healthlake/src/protocols/Aws_json1_0.ts b/clients/client-healthlake/src/protocols/Aws_json1_0.ts index 618593604b988..7715605ad4bf8 100644 --- a/clients/client-healthlake/src/protocols/Aws_json1_0.ts +++ b/clients/client-healthlake/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1028,54 +1033,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `HealthLake.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-honeycode/src/protocols/Aws_restJson1.ts b/clients/client-honeycode/src/protocols/Aws_restJson1.ts index 0fe8cc9bf1043..cc70f6fe7c6c3 100644 --- a/clients/client-honeycode/src/protocols/Aws_restJson1.ts +++ b/clients/client-honeycode/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1159,54 +1160,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iam/package.json b/clients/client-iam/package.json index 8e0003e81789f..2429d03c5d4f5 100644 --- a/clients/client-iam/package.json +++ b/clients/client-iam/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-iam/src/protocols/Aws_query.ts b/clients/client-iam/src/protocols/Aws_query.ts index 4dab7aed84089..d1b148fd0190c 100644 --- a/clients/client-iam/src/protocols/Aws_query.ts +++ b/clients/client-iam/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseInt32 as __strictParseInt32, @@ -19,7 +19,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddClientIDToOpenIDConnectProviderCommandInput, @@ -13836,41 +13835,6 @@ const _e = "entry"; const _m = "message"; const _me = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-identitystore/src/protocols/Aws_json1_1.ts b/clients/client-identitystore/src/protocols/Aws_json1_1.ts index 634d8bdcd467b..0d3e5226f9c6f 100644 --- a/clients/client-identitystore/src/protocols/Aws_json1_1.ts +++ b/clients/client-identitystore/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1139,54 +1140,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSIdentityStore.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-imagebuilder/src/protocols/Aws_restJson1.ts b/clients/client-imagebuilder/src/protocols/Aws_restJson1.ts index c18a4320cde86..9bb7cb9c049bf 100644 --- a/clients/client-imagebuilder/src/protocols/Aws_restJson1.ts +++ b/clients/client-imagebuilder/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4766,54 +4767,3 @@ const _sEI = "stepExecutionId"; const _tK = "tagKeys"; const _wBVA = "workflowBuildVersionArn"; const _wEI = "workflowExecutionId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-inspector-scan/src/protocols/Aws_restJson1.ts b/clients/client-inspector-scan/src/protocols/Aws_restJson1.ts index 44df72d40a9a7..0ca0515dfc9af 100644 --- a/clients/client-inspector-scan/src/protocols/Aws_restJson1.ts +++ b/clients/client-inspector-scan/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -226,54 +227,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-inspector/src/protocols/Aws_json1_1.ts b/clients/client-inspector/src/protocols/Aws_json1_1.ts index ecd581a9f63ed..6d2044cae9f47 100644 --- a/clients/client-inspector/src/protocols/Aws_json1_1.ts +++ b/clients/client-inspector/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2331,54 +2332,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `InspectorService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-inspector2/src/protocols/Aws_restJson1.ts b/clients/client-inspector2/src/protocols/Aws_restJson1.ts index 32aa377a35665..1caa763ff4073 100644 --- a/clients/client-inspector2/src/protocols/Aws_restJson1.ts +++ b/clients/client-inspector2/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4585,54 +4590,3 @@ const _rT = "resourceType"; const _ra = "retry-after"; const _sT = "scanType"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-internetmonitor/src/protocols/Aws_restJson1.ts b/clients/client-internetmonitor/src/protocols/Aws_restJson1.ts index 6222692781f7e..c17541da0e405 100644 --- a/clients/client-internetmonitor/src/protocols/Aws_restJson1.ts +++ b/clients/client-internetmonitor/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1152,54 +1153,3 @@ const _NT = "NextToken"; const _ST = "StartTime"; const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-1click-devices-service/src/protocols/Aws_restJson1.ts b/clients/client-iot-1click-devices-service/src/protocols/Aws_restJson1.ts index 4fe9761b1ec1f..51a56ad1f3f7d 100644 --- a/clients/client-iot-1click-devices-service/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-1click-devices-service/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -903,54 +904,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; const _tTS = "toTimeStamp"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-1click-projects/src/protocols/Aws_restJson1.ts b/clients/client-iot-1click-projects/src/protocols/Aws_restJson1.ts index 3b3f27d56bf65..8cc579edb3861 100644 --- a/clients/client-iot-1click-projects/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-1click-projects/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -956,54 +957,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-data-plane/src/protocols/Aws_restJson1.ts b/clients/client-iot-data-plane/src/protocols/Aws_restJson1.ts index e43e3d27f710b..5189df61fce89 100644 --- a/clients/client-iot-data-plane/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-data-plane/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -628,54 +629,3 @@ const _uP = "userProperties"; const _xamcd = "x-amz-mqtt5-correlation-data"; const _xampfi = "x-amz-mqtt5-payload-format-indicator"; const _xamup = "x-amz-mqtt5-user-properties"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-events-data/src/protocols/Aws_restJson1.ts b/clients/client-iot-events-data/src/protocols/Aws_restJson1.ts index fbbc87bf94abf..9c40dd4f377f1 100644 --- a/clients/client-iot-events-data/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-events-data/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -957,54 +958,3 @@ const _kV = "keyValue"; const _mR = "maxResults"; const _nT = "nextToken"; const _sN = "stateName"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-events/src/protocols/Aws_restJson1.ts b/clients/client-iot-events/src/protocols/Aws_restJson1.ts index 3c4c927b40444..fb2cef3321c46 100644 --- a/clients/client-iot-events/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-events/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1955,54 +1956,3 @@ const _nT = "nextToken"; const _rA = "resourceArn"; const _tK = "tagKeys"; const _v = "version"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-jobs-data-plane/src/protocols/Aws_restJson1.ts b/clients/client-iot-jobs-data-plane/src/protocols/Aws_restJson1.ts index cfe37d28e58ad..7c81979296567 100644 --- a/clients/client-iot-jobs-data-plane/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-jobs-data-plane/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -434,54 +435,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _eN = "executionNumber"; const _iJD = "includeJobDocument"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-roborunner/src/protocols/Aws_restJson1.ts b/clients/client-iot-roborunner/src/protocols/Aws_restJson1.ts index db61fcfac9bdc..8af586f128a3b 100644 --- a/clients/client-iot-roborunner/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-roborunner/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1364,54 +1369,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _s = "site"; const _st = "state"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot-wireless/src/protocols/Aws_restJson1.ts b/clients/client-iot-wireless/src/protocols/Aws_restJson1.ts index a9ff2c8c5d238..d2dd0c25b3c43 100644 --- a/clients/client-iot-wireless/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot-wireless/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -5963,54 +5964,3 @@ const _sT = "serviceType"; const _tDT = "taskDefinitionType"; const _tK = "tagKeys"; const _wDT = "wirelessDeviceType"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iot/src/protocols/Aws_restJson1.ts b/clients/client-iot/src/protocols/Aws_restJson1.ts index 07a8761b87c89..89390cdf27f28 100644 --- a/clients/client-iot/src/protocols/Aws_restJson1.ts +++ b/clients/client-iot/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -14916,54 +14917,3 @@ const _xaip = "x-amzn-iot-principal"; const _xaip_ = "x-amzn-iot-policy"; const _xap = "x-amzn-principal"; const _xat = "x-amz-tagging"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iotanalytics/src/protocols/Aws_restJson1.ts b/clients/client-iotanalytics/src/protocols/Aws_restJson1.ts index ff56d68693d19..d752ed9f9271f 100644 --- a/clients/client-iotanalytics/src/protocols/Aws_restJson1.ts +++ b/clients/client-iotanalytics/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2445,54 +2450,3 @@ const _sOOA = "scheduledOnOrAfter"; const _sT = "startTime"; const _tK = "tagKeys"; const _vI = "versionId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iotdeviceadvisor/src/protocols/Aws_restJson1.ts b/clients/client-iotdeviceadvisor/src/protocols/Aws_restJson1.ts index 802515ee4d7fd..5ca92accdc5b4 100644 --- a/clients/client-iotdeviceadvisor/src/protocols/Aws_restJson1.ts +++ b/clients/client-iotdeviceadvisor/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -938,54 +939,3 @@ const _sDI = "suiteDefinitionId"; const _sDV = "suiteDefinitionVersion"; const _tA = "thingArn"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iotfleethub/src/protocols/Aws_restJson1.ts b/clients/client-iotfleethub/src/protocols/Aws_restJson1.ts index 44cfacc0c85b0..1552aca2e985a 100644 --- a/clients/client-iotfleethub/src/protocols/Aws_restJson1.ts +++ b/clients/client-iotfleethub/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -559,54 +560,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _cT = "clientToken"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iotfleetwise/src/protocols/Aws_json1_0.ts b/clients/client-iotfleetwise/src/protocols/Aws_json1_0.ts index 15de253894bff..c10ba1880b9b3 100644 --- a/clients/client-iotfleetwise/src/protocols/Aws_json1_0.ts +++ b/clients/client-iotfleetwise/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3620,54 +3625,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `IoTAutobahnControlPlane.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iotsecuretunneling/src/protocols/Aws_json1_1.ts b/clients/client-iotsecuretunneling/src/protocols/Aws_json1_1.ts index 93bc981815022..039ed121f9a78 100644 --- a/clients/client-iotsecuretunneling/src/protocols/Aws_json1_1.ts +++ b/clients/client-iotsecuretunneling/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -547,54 +548,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `IoTSecuredTunneling.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iotsitewise/src/protocols/Aws_restJson1.ts b/clients/client-iotsitewise/src/protocols/Aws_restJson1.ts index cfedcec9fba5e..0924f97f697fa 100644 --- a/clients/client-iotsitewise/src/protocols/Aws_restJson1.ts +++ b/clients/client-iotsitewise/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -6256,54 +6257,3 @@ const _tRI = "targetResourceId"; const _tRT = "targetResourceType"; const _tST = "timeSeriesType"; const _tT = "traversalType"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iotthingsgraph/src/protocols/Aws_json1_1.ts b/clients/client-iotthingsgraph/src/protocols/Aws_json1_1.ts index 2cc5fca97843e..0be03a3f88126 100644 --- a/clients/client-iotthingsgraph/src/protocols/Aws_json1_1.ts +++ b/clients/client-iotthingsgraph/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2123,54 +2124,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `IotThingsGraphFrontEndService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-iottwinmaker/src/protocols/Aws_restJson1.ts b/clients/client-iottwinmaker/src/protocols/Aws_restJson1.ts index 17a83c1c852e1..821cfd9d65ea6 100644 --- a/clients/client-iottwinmaker/src/protocols/Aws_restJson1.ts +++ b/clients/client-iottwinmaker/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -3726,54 +3727,3 @@ const _rARN = "resourceARN"; const _tK = "tagKeys"; const _w = "workspace"; const _wI = "workspaceId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ivs-realtime/src/protocols/Aws_restJson1.ts b/clients/client-ivs-realtime/src/protocols/Aws_restJson1.ts index ad89d11475070..f9297d14ed6cd 100644 --- a/clients/client-ivs-realtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-ivs-realtime/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1820,54 +1821,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ivs/src/protocols/Aws_restJson1.ts b/clients/client-ivs/src/protocols/Aws_restJson1.ts index 2cd26160eface..2608308f6fa5c 100644 --- a/clients/client-ivs/src/protocols/Aws_restJson1.ts +++ b/clients/client-ivs/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2102,54 +2103,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ivschat/src/protocols/Aws_restJson1.ts b/clients/client-ivschat/src/protocols/Aws_restJson1.ts index d72ca869141c9..b2b0cdedc9be4 100644 --- a/clients/client-ivschat/src/protocols/Aws_restJson1.ts +++ b/clients/client-ivschat/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1184,54 +1189,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kafka/src/protocols/Aws_restJson1.ts b/clients/client-kafka/src/protocols/Aws_restJson1.ts index ef38bfec34719..6ccea78a90364 100644 --- a/clients/client-kafka/src/protocols/Aws_restJson1.ts +++ b/clients/client-kafka/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4385,54 +4386,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _rNF = "replicatorNameFilter"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kafkaconnect/src/protocols/Aws_restJson1.ts b/clients/client-kafkaconnect/src/protocols/Aws_restJson1.ts index f173cf4433ba5..848340b42a6fd 100644 --- a/clients/client-kafkaconnect/src/protocols/Aws_restJson1.ts +++ b/clients/client-kafkaconnect/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1259,54 +1260,3 @@ const _mR = "maxResults"; const _nP = "namePrefix"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kendra-ranking/src/protocols/Aws_json1_0.ts b/clients/client-kendra-ranking/src/protocols/Aws_json1_0.ts index c597fb16e35f6..763db267b837a 100644 --- a/clients/client-kendra-ranking/src/protocols/Aws_json1_0.ts +++ b/clients/client-kendra-ranking/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -773,54 +774,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSKendraRerankingFrontendService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kendra/src/protocols/Aws_json1_1.ts b/clients/client-kendra/src/protocols/Aws_json1_1.ts index 9caed4979577b..c9211a7876909 100644 --- a/clients/client-kendra/src/protocols/Aws_json1_1.ts +++ b/clients/client-kendra/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -5134,54 +5135,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSKendraFrontendService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-keyspaces/src/protocols/Aws_json1_0.ts b/clients/client-keyspaces/src/protocols/Aws_json1_0.ts index 80c9d0c801936..bd92102a31362 100644 --- a/clients/client-keyspaces/src/protocols/Aws_json1_0.ts +++ b/clients/client-keyspaces/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1141,54 +1142,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `KeyspacesService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis-analytics-v2/src/protocols/Aws_json1_1.ts b/clients/client-kinesis-analytics-v2/src/protocols/Aws_json1_1.ts index 6aae98d980ba7..88f1a86183ec1 100644 --- a/clients/client-kinesis-analytics-v2/src/protocols/Aws_json1_1.ts +++ b/clients/client-kinesis-analytics-v2/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2296,54 +2297,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `KinesisAnalytics_20180523.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis-analytics/src/protocols/Aws_json1_1.ts b/clients/client-kinesis-analytics/src/protocols/Aws_json1_1.ts index 9681827a1a5a7..6983f513df707 100644 --- a/clients/client-kinesis-analytics/src/protocols/Aws_json1_1.ts +++ b/clients/client-kinesis-analytics/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1412,54 +1413,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `KinesisAnalytics_20150814.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis-video-archived-media/src/protocols/Aws_restJson1.ts b/clients/client-kinesis-video-archived-media/src/protocols/Aws_restJson1.ts index 30ad4893fa0e8..2fc439851ef57 100644 --- a/clients/client-kinesis-video-archived-media/src/protocols/Aws_restJson1.ts +++ b/clients/client-kinesis-video-archived-media/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -734,54 +735,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _CT = "ContentType"; const _ct = "content-type"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis-video-media/src/protocols/Aws_restJson1.ts b/clients/client-kinesis-video-media/src/protocols/Aws_restJson1.ts index ff96d63656c40..1d50a7605cb2b 100644 --- a/clients/client-kinesis-video-media/src/protocols/Aws_restJson1.ts +++ b/clients/client-kinesis-video-media/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -265,54 +266,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _CT = "ContentType"; const _ct = "content-type"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis-video-signaling/src/protocols/Aws_restJson1.ts b/clients/client-kinesis-video-signaling/src/protocols/Aws_restJson1.ts index 5287d0b6b591f..41df64ebca89b 100644 --- a/clients/client-kinesis-video-signaling/src/protocols/Aws_restJson1.ts +++ b/clients/client-kinesis-video-signaling/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -307,54 +308,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis-video-webrtc-storage/src/protocols/Aws_restJson1.ts b/clients/client-kinesis-video-webrtc-storage/src/protocols/Aws_restJson1.ts index 0d67f9bb61050..578b2e86080a4 100644 --- a/clients/client-kinesis-video-webrtc-storage/src/protocols/Aws_restJson1.ts +++ b/clients/client-kinesis-video-webrtc-storage/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -195,54 +196,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis-video/src/protocols/Aws_restJson1.ts b/clients/client-kinesis-video/src/protocols/Aws_restJson1.ts index 0e14d23fc441d..31a72f0fe7b99 100644 --- a/clients/client-kinesis-video/src/protocols/Aws_restJson1.ts +++ b/clients/client-kinesis-video/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2055,54 +2056,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kinesis/src/protocols/Aws_json1_1.ts b/clients/client-kinesis/src/protocols/Aws_json1_1.ts index 6f331324b7c4e..b407c6cf2b958 100644 --- a/clients/client-kinesis/src/protocols/Aws_json1_1.ts +++ b/clients/client-kinesis/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2156,54 +2157,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Kinesis_20131202.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-kms/src/protocols/Aws_json1_1.ts b/clients/client-kms/src/protocols/Aws_json1_1.ts index c199319a404e5..6f63193ade0b5 100644 --- a/clients/client-kms/src/protocols/Aws_json1_1.ts +++ b/clients/client-kms/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3540,54 +3541,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `TrentService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lakeformation/src/protocols/Aws_restJson1.ts b/clients/client-lakeformation/src/protocols/Aws_restJson1.ts index cc48dc173a9ca..0ef6c3550c1f2 100644 --- a/clients/client-lakeformation/src/protocols/Aws_restJson1.ts +++ b/clients/client-lakeformation/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -3440,54 +3441,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lambda/src/protocols/Aws_restJson1.ts b/clients/client-lambda/src/protocols/Aws_restJson1.ts index a18f83b072b73..d02617d9fecdd 100644 --- a/clients/client-lambda/src/protocols/Aws_restJson1.ts +++ b/clients/client-lambda/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4912,54 +4913,3 @@ const _xafe = "x-amz-function-error"; const _xait = "x-amz-invocation-type"; const _xalr = "x-amz-log-result"; const _xalt = "x-amz-log-type"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-launch-wizard/src/protocols/Aws_restJson1.ts b/clients/client-launch-wizard/src/protocols/Aws_restJson1.ts index 6de2a9b716ec6..b98ea59b31ab3 100644 --- a/clients/client-launch-wizard/src/protocols/Aws_restJson1.ts +++ b/clients/client-launch-wizard/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -622,54 +623,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lex-model-building-service/src/protocols/Aws_restJson1.ts b/clients/client-lex-model-building-service/src/protocols/Aws_restJson1.ts index ed9f333916001..cd4f7d8e58ad9 100644 --- a/clients/client-lex-model-building-service/src/protocols/Aws_restJson1.ts +++ b/clients/client-lex-model-building-service/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2646,54 +2647,3 @@ const _tK = "tagKeys"; const _v = "version"; const _vBNC = "v1BotNameContains"; const _vi = "view"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lex-models-v2/src/protocols/Aws_restJson1.ts b/clients/client-lex-models-v2/src/protocols/Aws_restJson1.ts index 0dbc6dd048cf2..b0ef66c072372 100644 --- a/clients/client-lex-models-v2/src/protocols/Aws_restJson1.ts +++ b/clients/client-lex-models-v2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -8245,54 +8246,3 @@ const _ra = "retry-after"; const _sI = "sessionId"; const _sRIUC = "skipResourceInUseCheck"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lex-runtime-service/src/protocols/Aws_restJson1.ts b/clients/client-lex-runtime-service/src/protocols/Aws_restJson1.ts index 5db9194fbb299..0f1ed44995f3c 100644 --- a/clients/client-lex-runtime-service/src/protocols/Aws_restJson1.ts +++ b/clients/client-lex-runtime-service/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -754,54 +755,3 @@ const _xals_ = "x-amz-lex-sentiment"; const _xalsa = "x-amz-lex-session-attributes"; const _xalsi = "x-amz-lex-session-id"; const _xalste = "x-amz-lex-slot-to-elicit"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lex-runtime-v2/src/protocols/Aws_restJson1.ts b/clients/client-lex-runtime-v2/src/protocols/Aws_restJson1.ts index 244a8c04e4b43..be11a1449cc26 100644 --- a/clients/client-lex-runtime-v2/src/protocols/Aws_restJson1.ts +++ b/clients/client-lex-runtime-v2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1330,54 +1331,3 @@ const _xalra = "x-amz-lex-request-attributes"; const _xalrbm = "x-amz-lex-recognized-bot-member"; const _xalsi = "x-amz-lex-session-id"; const _xalss = "x-amz-lex-session-state"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-license-manager-linux-subscriptions/src/protocols/Aws_restJson1.ts b/clients/client-license-manager-linux-subscriptions/src/protocols/Aws_restJson1.ts index 663bd93a1caac..759c056278d95 100644 --- a/clients/client-license-manager-linux-subscriptions/src/protocols/Aws_restJson1.ts +++ b/clients/client-license-manager-linux-subscriptions/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -350,54 +351,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-license-manager-user-subscriptions/src/protocols/Aws_restJson1.ts b/clients/client-license-manager-user-subscriptions/src/protocols/Aws_restJson1.ts index 036ab5173abec..962d9e0408d53 100644 --- a/clients/client-license-manager-user-subscriptions/src/protocols/Aws_restJson1.ts +++ b/clients/client-license-manager-user-subscriptions/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -805,54 +806,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-license-manager/src/protocols/Aws_json1_1.ts b/clients/client-license-manager/src/protocols/Aws_json1_1.ts index 6c42fdb50b8cd..f8194159169da 100644 --- a/clients/client-license-manager/src/protocols/Aws_json1_1.ts +++ b/clients/client-license-manager/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2949,54 +2950,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSLicenseManager.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lightsail/src/protocols/Aws_json1_1.ts b/clients/client-lightsail/src/protocols/Aws_json1_1.ts index 4b2d1d1fb20a9..d012d87812ac8 100644 --- a/clients/client-lightsail/src/protocols/Aws_json1_1.ts +++ b/clients/client-lightsail/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -9961,54 +9962,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Lightsail_20161128.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-location/src/protocols/Aws_restJson1.ts b/clients/client-location/src/protocols/Aws_restJson1.ts index 3e6c01cda69f9..5eed33655e2ba 100644 --- a/clients/client-location/src/protocols/Aws_restJson1.ts +++ b/clients/client-location/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -4442,54 +4443,3 @@ const _fD = "forceDelete"; const _k = "key"; const _l = "language"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lookoutequipment/src/protocols/Aws_json1_0.ts b/clients/client-lookoutequipment/src/protocols/Aws_json1_0.ts index 7b1bb322911a7..d17b5a4837165 100644 --- a/clients/client-lookoutequipment/src/protocols/Aws_json1_0.ts +++ b/clients/client-lookoutequipment/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3064,54 +3065,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSLookoutEquipmentFrontendService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lookoutmetrics/src/protocols/Aws_restJson1.ts b/clients/client-lookoutmetrics/src/protocols/Aws_restJson1.ts index e5f4dc0832b12..d5ebd3f01c50c 100644 --- a/clients/client-lookoutmetrics/src/protocols/Aws_restJson1.ts +++ b/clients/client-lookoutmetrics/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2261,54 +2262,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-lookoutvision/src/protocols/Aws_restJson1.ts b/clients/client-lookoutvision/src/protocols/Aws_restJson1.ts index e06f1d3062225..d80bbf6c3546c 100644 --- a/clients/client-lookoutvision/src/protocols/Aws_restJson1.ts +++ b/clients/client-lookoutvision/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1520,54 +1521,3 @@ const _ra = "retry-after"; const _sRC = "sourceRefContains"; const _tK = "tagKeys"; const _xact = "x-amzn-client-token"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-m2/src/protocols/Aws_restJson1.ts b/clients/client-m2/src/protocols/Aws_restJson1.ts index 8fbc4ba1db809..55fff8473b3fb 100644 --- a/clients/client-m2/src/protocols/Aws_restJson1.ts +++ b/clients/client-m2/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2228,54 +2233,3 @@ const _s = "status"; const _sA = "startedAfter"; const _sB = "startedBefore"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-machine-learning/src/protocols/Aws_json1_1.ts b/clients/client-machine-learning/src/protocols/Aws_json1_1.ts index 3ce5b7ab2b9a3..ad0c7d09c01e1 100644 --- a/clients/client-machine-learning/src/protocols/Aws_json1_1.ts +++ b/clients/client-machine-learning/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1804,54 +1805,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonML_20141212.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-macie2/src/protocols/Aws_restJson1.ts b/clients/client-macie2/src/protocols/Aws_restJson1.ts index 40e2e0f8ce7f5..2ffc2b3c83f9d 100644 --- a/clients/client-macie2/src/protocols/Aws_restJson1.ts +++ b/clients/client-macie2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -6554,54 +6555,3 @@ const _oA = "onlyAssociated"; const _rA = "resourceArn"; const _tK = "tagKeys"; const _tR = "timeRange"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-managedblockchain-query/src/protocols/Aws_restJson1.ts b/clients/client-managedblockchain-query/src/protocols/Aws_restJson1.ts index 64e6f5bd39132..164b380d5d0b6 100644 --- a/clients/client-managedblockchain-query/src/protocols/Aws_restJson1.ts +++ b/clients/client-managedblockchain-query/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -831,54 +832,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-managedblockchain/src/protocols/Aws_restJson1.ts b/clients/client-managedblockchain/src/protocols/Aws_restJson1.ts index 3202fd39e47d8..0589df41a1d5f 100644 --- a/clients/client-managedblockchain/src/protocols/Aws_restJson1.ts +++ b/clients/client-managedblockchain/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1837,54 +1838,3 @@ const _nT = "nextToken"; const _nTe = "networkType"; const _s = "status"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-marketplace-agreement/src/protocols/Aws_json1_0.ts b/clients/client-marketplace-agreement/src/protocols/Aws_json1_0.ts index 3e7857bd86cae..a005f5f823786 100644 --- a/clients/client-marketplace-agreement/src/protocols/Aws_json1_0.ts +++ b/clients/client-marketplace-agreement/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -571,54 +576,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSMPCommerceService_v20200301.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-marketplace-catalog/src/protocols/Aws_restJson1.ts b/clients/client-marketplace-catalog/src/protocols/Aws_restJson1.ts index 970cd9c5b6c09..74c94efc709a4 100644 --- a/clients/client-marketplace-catalog/src/protocols/Aws_restJson1.ts +++ b/clients/client-marketplace-catalog/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1257,54 +1258,3 @@ const _c = "catalog"; const _cSI = "changeSetId"; const _eI = "entityId"; const _rA = "resourceArn"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-marketplace-commerce-analytics/src/protocols/Aws_json1_1.ts b/clients/client-marketplace-commerce-analytics/src/protocols/Aws_json1_1.ts index ad8dc2610c314..217d97738e0a4 100644 --- a/clients/client-marketplace-commerce-analytics/src/protocols/Aws_json1_1.ts +++ b/clients/client-marketplace-commerce-analytics/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -212,54 +213,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `MarketplaceCommerceAnalytics20150701.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-marketplace-deployment/src/protocols/Aws_restJson1.ts b/clients/client-marketplace-deployment/src/protocols/Aws_restJson1.ts index 0f0338bd3eb8e..4dd2407b23e2f 100644 --- a/clients/client-marketplace-deployment/src/protocols/Aws_restJson1.ts +++ b/clients/client-marketplace-deployment/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -416,54 +417,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-marketplace-entitlement-service/src/protocols/Aws_json1_1.ts b/clients/client-marketplace-entitlement-service/src/protocols/Aws_json1_1.ts index aef63e168359b..925039dead33e 100644 --- a/clients/client-marketplace-entitlement-service/src/protocols/Aws_json1_1.ts +++ b/clients/client-marketplace-entitlement-service/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -243,54 +244,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSMPEntitlementService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-marketplace-metering/src/protocols/Aws_json1_1.ts b/clients/client-marketplace-metering/src/protocols/Aws_json1_1.ts index 4bf65ccad2153..fdd25251da740 100644 --- a/clients/client-marketplace-metering/src/protocols/Aws_json1_1.ts +++ b/clients/client-marketplace-metering/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -740,54 +741,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSMPMeteringService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediaconnect/src/protocols/Aws_restJson1.ts b/clients/client-mediaconnect/src/protocols/Aws_restJson1.ts index 29caaf0a28a54..9e5b5181f276c 100644 --- a/clients/client-mediaconnect/src/protocols/Aws_restJson1.ts +++ b/clients/client-mediaconnect/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4219,54 +4220,3 @@ const _fA = "filterArn"; const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediaconvert/src/protocols/Aws_restJson1.ts b/clients/client-mediaconvert/src/protocols/Aws_restJson1.ts index c8c41854376ba..2576c7516ffd1 100644 --- a/clients/client-mediaconvert/src/protocols/Aws_restJson1.ts +++ b/clients/client-mediaconvert/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -7592,54 +7593,3 @@ const _nT = "nextToken"; const _o = "order"; const _q = "queue"; const _s = "status"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-medialive/src/protocols/Aws_restJson1.ts b/clients/client-medialive/src/protocols/Aws_restJson1.ts index 7804d31089b5f..ca3f886ebd63f 100644 --- a/clients/client-medialive/src/protocols/Aws_restJson1.ts +++ b/clients/client-medialive/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -9914,54 +9915,3 @@ const _tK = "tagKeys"; const _tT = "thumbnailType"; const _tTr = "transferType"; const _vQ = "videoQuality"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediapackage-vod/src/protocols/Aws_restJson1.ts b/clients/client-mediapackage-vod/src/protocols/Aws_restJson1.ts index 0aa9df9b45f8a..20f6d65ba2d0f 100644 --- a/clients/client-mediapackage-vod/src/protocols/Aws_restJson1.ts +++ b/clients/client-mediapackage-vod/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1581,54 +1582,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _pGI = "packagingGroupId"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediapackage/src/protocols/Aws_restJson1.ts b/clients/client-mediapackage/src/protocols/Aws_restJson1.ts index e85dc8fb80d6d..3ab3bc664dbfd 100644 --- a/clients/client-mediapackage/src/protocols/Aws_restJson1.ts +++ b/clients/client-mediapackage/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1771,54 +1772,3 @@ const _iS = "includeStatus"; const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediapackagev2/src/protocols/Aws_restJson1.ts b/clients/client-mediapackagev2/src/protocols/Aws_restJson1.ts index 0439b1662a48a..4115b267a45ea 100644 --- a/clients/client-mediapackagev2/src/protocols/Aws_restJson1.ts +++ b/clients/client-mediapackagev2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1632,54 +1633,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; const _xact = "x-amzn-client-token"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediastore-data/src/protocols/Aws_restJson1.ts b/clients/client-mediastore-data/src/protocols/Aws_restJson1.ts index 2ca9232994a68..af325571e2363 100644 --- a/clients/client-mediastore-data/src/protocols/Aws_restJson1.ts +++ b/clients/client-mediastore-data/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -423,54 +424,3 @@ const _lm = "last-modified"; const _r = "range"; const _xasc = "x-amz-storage-class"; const _xaua = "x-amz-upload-availability"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediastore/src/protocols/Aws_json1_1.ts b/clients/client-mediastore/src/protocols/Aws_json1_1.ts index 22f4143af0543..ccf0c7c022316 100644 --- a/clients/client-mediastore/src/protocols/Aws_json1_1.ts +++ b/clients/client-mediastore/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1146,54 +1147,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `MediaStore_20170901.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mediatailor/src/protocols/Aws_restJson1.ts b/clients/client-mediatailor/src/protocols/Aws_restJson1.ts index 89b1a2f960b32..37ef4c906b025 100644 --- a/clients/client-mediatailor/src/protocols/Aws_restJson1.ts +++ b/clients/client-mediatailor/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2660,54 +2661,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _rA = "resourceArn"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-medical-imaging/src/protocols/Aws_restJson1.ts b/clients/client-medical-imaging/src/protocols/Aws_restJson1.ts index 6347242c09afc..f996f6f6bf5d6 100644 --- a/clients/client-medical-imaging/src/protocols/Aws_restJson1.ts +++ b/clients/client-medical-imaging/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -1418,54 +1419,3 @@ const _nT = "nextToken"; const _tK = "tagKeys"; const _v = "version"; const _vI = "versionId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-memorydb/src/protocols/Aws_json1_1.ts b/clients/client-memorydb/src/protocols/Aws_json1_1.ts index da31a51eae2aa..1f3b7d902a271 100644 --- a/clients/client-memorydb/src/protocols/Aws_json1_1.ts +++ b/clients/client-memorydb/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3343,54 +3344,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonMemoryDB.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mgn/src/protocols/Aws_restJson1.ts b/clients/client-mgn/src/protocols/Aws_restJson1.ts index 536b83b835310..1f97c2d4fdfc0 100644 --- a/clients/client-mgn/src/protocols/Aws_restJson1.ts +++ b/clients/client-mgn/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4324,54 +4325,3 @@ const _nT = "nextToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-migration-hub-refactor-spaces/src/protocols/Aws_restJson1.ts b/clients/client-migration-hub-refactor-spaces/src/protocols/Aws_restJson1.ts index 55a245f6e8119..7ff629ddc4a80 100644 --- a/clients/client-migration-hub-refactor-spaces/src/protocols/Aws_restJson1.ts +++ b/clients/client-migration-hub-refactor-spaces/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1646,54 +1647,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-migration-hub/src/protocols/Aws_json1_1.ts b/clients/client-migration-hub/src/protocols/Aws_json1_1.ts index 20769dee69950..cec76904e408f 100644 --- a/clients/client-migration-hub/src/protocols/Aws_json1_1.ts +++ b/clients/client-migration-hub/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1164,54 +1165,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSMigrationHub.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-migrationhub-config/src/protocols/Aws_json1_1.ts b/clients/client-migrationhub-config/src/protocols/Aws_json1_1.ts index d9606685d2cc2..5519d4ce5e4fb 100644 --- a/clients/client-migrationhub-config/src/protocols/Aws_json1_1.ts +++ b/clients/client-migrationhub-config/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -423,54 +424,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSMigrationHubMultiAccountService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-migrationhuborchestrator/src/protocols/Aws_restJson1.ts b/clients/client-migrationhuborchestrator/src/protocols/Aws_restJson1.ts index 21708d34e4640..4ccc93fd954c4 100644 --- a/clients/client-migrationhuborchestrator/src/protocols/Aws_restJson1.ts +++ b/clients/client-migrationhuborchestrator/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1829,54 +1830,3 @@ const _sGI = "stepGroupId"; const _tI = "templateId"; const _tK = "tagKeys"; const _wI = "workflowId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-migrationhubstrategy/src/protocols/Aws_restJson1.ts b/clients/client-migrationhubstrategy/src/protocols/Aws_restJson1.ts index 7fed7dd775997..342fb7074c259 100644 --- a/clients/client-migrationhubstrategy/src/protocols/Aws_restJson1.ts +++ b/clients/client-migrationhubstrategy/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1649,54 +1650,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _mR = "maxResults"; const _nT = "nextToken"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mobile/src/protocols/Aws_restJson1.ts b/clients/client-mobile/src/protocols/Aws_restJson1.ts index 3109d5ed93253..81192939e8afd 100644 --- a/clients/client-mobile/src/protocols/Aws_restJson1.ts +++ b/clients/client-mobile/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -677,54 +678,3 @@ const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _sFR = "syncFromResources"; const _sI = "snapshotId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mq/src/protocols/Aws_restJson1.ts b/clients/client-mq/src/protocols/Aws_restJson1.ts index 31423a8f98c96..e3c2038dfdef5 100644 --- a/clients/client-mq/src/protocols/Aws_restJson1.ts +++ b/clients/client-mq/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1827,54 +1828,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _sT = "storageType"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mturk/src/protocols/Aws_json1_1.ts b/clients/client-mturk/src/protocols/Aws_json1_1.ts index f245cf5cc8fdf..84c23a3f45be5 100644 --- a/clients/client-mturk/src/protocols/Aws_json1_1.ts +++ b/clients/client-mturk/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2194,54 +2195,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `MTurkRequesterServiceV20170117.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-mwaa/src/protocols/Aws_restJson1.ts b/clients/client-mwaa/src/protocols/Aws_restJson1.ts index 8bf7dafb45738..8c2083dc72355 100644 --- a/clients/client-mwaa/src/protocols/Aws_restJson1.ts +++ b/clients/client-mwaa/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -881,54 +882,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _MR = "MaxResults"; const _NT = "NextToken"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-neptune-graph/src/protocols/Aws_restJson1.ts b/clients/client-neptune-graph/src/protocols/Aws_restJson1.ts index 9a8590a7cc786..b05669b6b4f8e 100644 --- a/clients/client-neptune-graph/src/protocols/Aws_restJson1.ts +++ b/clients/client-neptune-graph/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -1779,54 +1784,3 @@ const _nT = "nextToken"; const _s = "state"; const _sS = "skipSnapshot"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-neptune/package.json b/clients/client-neptune/package.json index a7b11664b49fa..70a2a79615590 100644 --- a/clients/client-neptune/package.json +++ b/clients/client-neptune/package.json @@ -59,7 +59,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-neptune/src/protocols/Aws_query.ts b/clients/client-neptune/src/protocols/Aws_query.ts index e87bb959a04a9..65a3048c3a53d 100644 --- a/clients/client-neptune/src/protocols/Aws_query.ts +++ b/clients/client-neptune/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, serializeFloat as __serializeFloat, @@ -21,7 +21,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddRoleToDBClusterCommandInput, AddRoleToDBClusterCommandOutput } from "../commands/AddRoleToDBClusterCommand"; import { @@ -10886,41 +10885,6 @@ const _Vp = "Vpc"; const _m = "message"; const _me = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-neptunedata/src/protocols/Aws_restJson1.ts b/clients/client-neptunedata/src/protocols/Aws_restJson1.ts index f28355f2d7c50..022f75fc3a1a9 100644 --- a/clients/client-neptunedata/src/protocols/Aws_restJson1.ts +++ b/clients/client-neptunedata/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3236,54 +3237,3 @@ const _oN = "opNum"; const _p = "page"; const _s = "silent"; const _se = "serializer"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-network-firewall/src/protocols/Aws_json1_0.ts b/clients/client-network-firewall/src/protocols/Aws_json1_0.ts index 5f111d001c920..a7bf99ffbdd4b 100644 --- a/clients/client-network-firewall/src/protocols/Aws_json1_0.ts +++ b/clients/client-network-firewall/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2423,54 +2424,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `NetworkFirewall_20201112.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-networkmanager/src/protocols/Aws_restJson1.ts b/clients/client-networkmanager/src/protocols/Aws_restJson1.ts index 372a4edd10a1c..f2213e96b2187 100644 --- a/clients/client-networkmanager/src/protocols/Aws_restJson1.ts +++ b/clients/client-networkmanager/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4845,54 +4846,3 @@ const _t = "type"; const _tGA = "transitGatewayArns"; const _tGCPA = "transitGatewayConnectPeerArns"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-networkmonitor/src/protocols/Aws_restJson1.ts b/clients/client-networkmonitor/src/protocols/Aws_restJson1.ts index 6e948d3d706f2..0874b9a9a3bbb 100644 --- a/clients/client-networkmonitor/src/protocols/Aws_restJson1.ts +++ b/clients/client-networkmonitor/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -834,54 +835,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _s = "state"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-nimble/src/protocols/Aws_restJson1.ts b/clients/client-nimble/src/protocols/Aws_restJson1.ts index 2f25c58ec2763..8e6e508846d60 100644 --- a/clients/client-nimble/src/protocols/Aws_restJson1.ts +++ b/clients/client-nimble/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2937,54 +2938,3 @@ const _sI = "sessionIds"; const _t = "types"; const _tK = "tagKeys"; const _xact = "x-amz-client-token"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-oam/src/protocols/Aws_restJson1.ts b/clients/client-oam/src/protocols/Aws_restJson1.ts index 2915ec7ca2428..97b33c634ef63 100644 --- a/clients/client-oam/src/protocols/Aws_restJson1.ts +++ b/clients/client-oam/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -970,54 +971,3 @@ const _TK = "TagKeys"; const _aET = "amznErrorType"; const _tK = "tagKeys"; const _xae = "x-amzn-errortype"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-omics/src/protocols/Aws_restJson1.ts b/clients/client-omics/src/protocols/Aws_restJson1.ts index cf5c28938e9ad..b43a92a9380a7 100644 --- a/clients/client-omics/src/protocols/Aws_restJson1.ts +++ b/clients/client-omics/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -5861,54 +5866,3 @@ const _s = "status"; const _sT = "startingToken"; const _t = "type"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-opensearch/src/protocols/Aws_restJson1.ts b/clients/client-opensearch/src/protocols/Aws_restJson1.ts index 19d3396980b37..988f78e843237 100644 --- a/clients/client-opensearch/src/protocols/Aws_restJson1.ts +++ b/clients/client-opensearch/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4318,54 +4323,3 @@ const _oI = "offeringId"; const _rAZ = "retrieveAZs"; const _rI = "reservationId"; const _s = "status"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-opensearchserverless/src/protocols/Aws_json1_0.ts b/clients/client-opensearchserverless/src/protocols/Aws_json1_0.ts index e4448c6431d11..53f55d863cad2 100644 --- a/clients/client-opensearchserverless/src/protocols/Aws_json1_0.ts +++ b/clients/client-opensearchserverless/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2162,54 +2163,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `OpenSearchServerless.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-opsworks/src/protocols/Aws_json1_1.ts b/clients/client-opsworks/src/protocols/Aws_json1_1.ts index 22b9ad6ebea5a..3aa8d72ff9c01 100644 --- a/clients/client-opsworks/src/protocols/Aws_json1_1.ts +++ b/clients/client-opsworks/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3200,54 +3201,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `OpsWorks_20130218.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-opsworkscm/src/protocols/Aws_json1_1.ts b/clients/client-opsworkscm/src/protocols/Aws_json1_1.ts index 0790d9054f677..4d61e35fcf6a0 100644 --- a/clients/client-opsworkscm/src/protocols/Aws_json1_1.ts +++ b/clients/client-opsworkscm/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1193,54 +1194,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `OpsWorksCM_V2016_11_01.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-organizations/src/protocols/Aws_json1_1.ts b/clients/client-organizations/src/protocols/Aws_json1_1.ts index e18d8f8d56aea..be03a755fbfbe 100644 --- a/clients/client-organizations/src/protocols/Aws_json1_1.ts +++ b/clients/client-organizations/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3678,54 +3679,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSOrganizationsV20161128.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-osis/src/protocols/Aws_restJson1.ts b/clients/client-osis/src/protocols/Aws_restJson1.ts index 21ba05203997f..23cc51dd410d7 100644 --- a/clients/client-osis/src/protocols/Aws_restJson1.ts +++ b/clients/client-osis/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1019,54 +1020,3 @@ const _NT = "NextToken"; const _a = "arn"; const _mR = "maxResults"; const _nT = "nextToken"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-outposts/src/protocols/Aws_restJson1.ts b/clients/client-outposts/src/protocols/Aws_restJson1.ts index 133eedfd91bb4..cc0f3007783be 100644 --- a/clients/client-outposts/src/protocols/Aws_restJson1.ts +++ b/clients/client-outposts/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1526,54 +1527,3 @@ const _SF = "StatusFilter"; const _SSF = "SupportedStorageFilter"; const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-panorama/src/protocols/Aws_restJson1.ts b/clients/client-panorama/src/protocols/Aws_restJson1.ts index ee438b4b843be..949b45e56d0bc 100644 --- a/clients/client-panorama/src/protocols/Aws_restJson1.ts +++ b/clients/client-panorama/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2234,54 +2239,3 @@ const _pVa = "patchVersion"; const _ra = "retry-after"; const _sF = "statusFilter"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-payment-cryptography-data/src/protocols/Aws_restJson1.ts b/clients/client-payment-cryptography-data/src/protocols/Aws_restJson1.ts index bb9480c7f917f..66fa0e02c370e 100644 --- a/clients/client-payment-cryptography-data/src/protocols/Aws_restJson1.ts +++ b/clients/client-payment-cryptography-data/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -899,54 +904,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-payment-cryptography/src/protocols/Aws_json1_0.ts b/clients/client-payment-cryptography/src/protocols/Aws_json1_0.ts index cc15f88d62427..4e44046c74f41 100644 --- a/clients/client-payment-cryptography/src/protocols/Aws_json1_0.ts +++ b/clients/client-payment-cryptography/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1211,54 +1212,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `PaymentCryptographyControlPlane.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pca-connector-ad/src/protocols/Aws_restJson1.ts b/clients/client-pca-connector-ad/src/protocols/Aws_restJson1.ts index 1f22897c7186d..786485e8ffb6e 100644 --- a/clients/client-pca-connector-ad/src/protocols/Aws_restJson1.ts +++ b/clients/client-pca-connector-ad/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1701,54 +1706,3 @@ const _MR = "MaxResults"; const _NT = "NextToken"; const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-personalize-events/src/protocols/Aws_restJson1.ts b/clients/client-personalize-events/src/protocols/Aws_restJson1.ts index c3f0ad87675d5..f47c3864d17f7 100644 --- a/clients/client-personalize-events/src/protocols/Aws_restJson1.ts +++ b/clients/client-personalize-events/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -474,54 +475,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-personalize-runtime/src/protocols/Aws_restJson1.ts b/clients/client-personalize-runtime/src/protocols/Aws_restJson1.ts index 70c41773e0675..7703e9644540d 100644 --- a/clients/client-personalize-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-personalize-runtime/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -335,54 +336,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-personalize/src/protocols/Aws_json1_1.ts b/clients/client-personalize/src/protocols/Aws_json1_1.ts index 7cdda0c5b65d5..bceaa4d78f5c4 100644 --- a/clients/client-personalize/src/protocols/Aws_json1_1.ts +++ b/clients/client-personalize/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4348,54 +4349,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonPersonalize.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pi/src/protocols/Aws_json1_1.ts b/clients/client-pi/src/protocols/Aws_json1_1.ts index 20e93d5ea8915..de8b30bef6df3 100644 --- a/clients/client-pi/src/protocols/Aws_json1_1.ts +++ b/clients/client-pi/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1059,54 +1060,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `PerformanceInsightsv20180227.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pinpoint-email/src/protocols/Aws_restJson1.ts b/clients/client-pinpoint-email/src/protocols/Aws_restJson1.ts index ee59edafed00b..a8b3d30eac7a9 100644 --- a/clients/client-pinpoint-email/src/protocols/Aws_restJson1.ts +++ b/clients/client-pinpoint-email/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2593,54 +2594,3 @@ const _PS = "PageSize"; const _RA = "ResourceArn"; const _SD = "StartDate"; const _TK = "TagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pinpoint-sms-voice-v2/src/protocols/Aws_json1_0.ts b/clients/client-pinpoint-sms-voice-v2/src/protocols/Aws_json1_0.ts index 95cb8697991fd..2f732cb24006b 100644 --- a/clients/client-pinpoint-sms-voice-v2/src/protocols/Aws_json1_0.ts +++ b/clients/client-pinpoint-sms-voice-v2/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4144,54 +4145,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `PinpointSMSVoiceV2.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pinpoint-sms-voice/src/protocols/Aws_restJson1.ts b/clients/client-pinpoint-sms-voice/src/protocols/Aws_restJson1.ts index d10c4e0851e74..8c667ef8ff19e 100644 --- a/clients/client-pinpoint-sms-voice/src/protocols/Aws_restJson1.ts +++ b/clients/client-pinpoint-sms-voice/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -587,54 +588,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _NT = "NextToken"; const _PS = "PageSize"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pinpoint/src/protocols/Aws_restJson1.ts b/clients/client-pinpoint/src/protocols/Aws_restJson1.ts index ed110f1a851ac..c14ba0c2647ed 100644 --- a/clients/client-pinpoint/src/protocols/Aws_restJson1.ts +++ b/clients/client-pinpoint/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -7449,54 +7450,3 @@ const _t = "token"; const _tK = "tagKeys"; const _tt = "template-type"; const _v = "version"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pipes/src/protocols/Aws_restJson1.ts b/clients/client-pipes/src/protocols/Aws_restJson1.ts index f48a83cbaa789..69148bd6ace7b 100644 --- a/clients/client-pipes/src/protocols/Aws_restJson1.ts +++ b/clients/client-pipes/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1191,54 +1192,3 @@ const _TP = "TargetPrefix"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-polly/src/protocols/Aws_restJson1.ts b/clients/client-polly/src/protocols/Aws_restJson1.ts index 5d3519836c447..6a42eeda3bf0b 100644 --- a/clients/client-polly/src/protocols/Aws_restJson1.ts +++ b/clients/client-polly/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1072,54 +1073,3 @@ const _RC = "RequestCharacters"; const _S = "Status"; const _ct = "content-type"; const _xar = "x-amzn-requestcharacters"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-pricing/src/protocols/Aws_json1_1.ts b/clients/client-pricing/src/protocols/Aws_json1_1.ts index 85be556b04706..9777fd63d56af 100644 --- a/clients/client-pricing/src/protocols/Aws_json1_1.ts +++ b/clients/client-pricing/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -484,54 +485,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSPriceListService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-privatenetworks/src/protocols/Aws_restJson1.ts b/clients/client-privatenetworks/src/protocols/Aws_restJson1.ts index 00ad8a895b70a..bb9a0cdaaaae9 100644 --- a/clients/client-privatenetworks/src/protocols/Aws_restJson1.ts +++ b/clients/client-privatenetworks/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1664,54 +1665,3 @@ const _cT = "clientToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-proton/src/protocols/Aws_json1_0.ts b/clients/client-proton/src/protocols/Aws_json1_0.ts index 224d2628abcfc..cfda5316cb2e1 100644 --- a/clients/client-proton/src/protocols/Aws_json1_0.ts +++ b/clients/client-proton/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -5409,54 +5414,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AwsProton20200720.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-qbusiness/src/protocols/Aws_restJson1.ts b/clients/client-qbusiness/src/protocols/Aws_restJson1.ts index 3ec8b554787fb..c7eec479fbe8f 100644 --- a/clients/client-qbusiness/src/protocols/Aws_restJson1.ts +++ b/clients/client-qbusiness/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3800,54 +3805,3 @@ const _tK = "tagKeys"; const _uET = "updatedEarlierThan"; const _uG = "userGroups"; const _uI = "userId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-qconnect/src/protocols/Aws_restJson1.ts b/clients/client-qconnect/src/protocols/Aws_restJson1.ts index 08c1f3ec8c862..14d62b2d34a4b 100644 --- a/clients/client-qconnect/src/protocols/Aws_restJson1.ts +++ b/clients/client-qconnect/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2662,54 +2667,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; const _wTS = "waitTimeSeconds"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-qldb-session/src/protocols/Aws_json1_0.ts b/clients/client-qldb-session/src/protocols/Aws_json1_0.ts index 35ade6b1883b1..aac611bbd2e1a 100644 --- a/clients/client-qldb-session/src/protocols/Aws_json1_0.ts +++ b/clients/client-qldb-session/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -420,54 +421,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `QLDBSession.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-qldb/src/protocols/Aws_restJson1.ts b/clients/client-qldb/src/protocols/Aws_restJson1.ts index a1ea73c18874d..a3c308f2300b8 100644 --- a/clients/client-qldb/src/protocols/Aws_restJson1.ts +++ b/clients/client-qldb/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1272,54 +1273,3 @@ const _TK = "TagKeys"; const _mr = "max_results"; const _nt = "next_token"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-quicksight/src/protocols/Aws_restJson1.ts b/clients/client-quicksight/src/protocols/Aws_restJson1.ts index 9262e04b4e75d..3229cee2c1ac9 100644 --- a/clients/client-quicksight/src/protocols/Aws_restJson1.ts +++ b/clients/client-quicksight/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -20334,54 +20339,3 @@ const _t = "type"; const _ua = "user-arn"; const _urd = "undo-redo-disabled"; const _vn = "version-number"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ram/src/protocols/Aws_restJson1.ts b/clients/client-ram/src/protocols/Aws_restJson1.ts index b8b80ca43a3ae..b4c2794e65bb3 100644 --- a/clients/client-ram/src/protocols/Aws_restJson1.ts +++ b/clients/client-ram/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2718,54 +2719,3 @@ const _cT = "clientToken"; const _pA = "permissionArn"; const _pV = "permissionVersion"; const _rSA = "resourceShareArn"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-rbin/src/protocols/Aws_restJson1.ts b/clients/client-rbin/src/protocols/Aws_restJson1.ts index 0818045b94ac5..43c8e66d3ce19 100644 --- a/clients/client-rbin/src/protocols/Aws_restJson1.ts +++ b/clients/client-rbin/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -689,54 +690,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-rds-data/src/protocols/Aws_restJson1.ts b/clients/client-rds-data/src/protocols/Aws_restJson1.ts index 67d4dc6ec24fd..ffdb9ca30c00c 100644 --- a/clients/client-rds-data/src/protocols/Aws_restJson1.ts +++ b/clients/client-rds-data/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1092,54 +1097,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-rds/package.json b/clients/client-rds/package.json index 44038985d9070..41e1254451bf7 100644 --- a/clients/client-rds/package.json +++ b/clients/client-rds/package.json @@ -59,7 +59,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-rds/src/protocols/Aws_query.ts b/clients/client-rds/src/protocols/Aws_query.ts index ed61c3c271cef..dfa95d2d28172 100644 --- a/clients/client-rds/src/protocols/Aws_query.ts +++ b/clients/client-rds/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, serializeFloat as __serializeFloat, @@ -22,7 +22,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddRoleToDBClusterCommandInput, AddRoleToDBClusterCommandOutput } from "../commands/AddRoleToDBClusterCommand"; import { @@ -25702,41 +25701,6 @@ const _e = "entry"; const _m = "message"; const _me = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-redshift-data/src/protocols/Aws_json1_1.ts b/clients/client-redshift-data/src/protocols/Aws_json1_1.ts index a4499d296400a..d806af1a2f3a3 100644 --- a/clients/client-redshift-data/src/protocols/Aws_json1_1.ts +++ b/clients/client-redshift-data/src/protocols/Aws_json1_1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -881,54 +886,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `RedshiftData.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-redshift-serverless/src/protocols/Aws_json1_1.ts b/clients/client-redshift-serverless/src/protocols/Aws_json1_1.ts index 05c68378d607e..6dc29c389106b 100644 --- a/clients/client-redshift-serverless/src/protocols/Aws_json1_1.ts +++ b/clients/client-redshift-serverless/src/protocols/Aws_json1_1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3303,54 +3308,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `RedshiftServerless.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-redshift/package.json b/clients/client-redshift/package.json index f9c4969571bad..2ce9c9b15a170 100644 --- a/clients/client-redshift/package.json +++ b/clients/client-redshift/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-redshift/src/protocols/Aws_query.ts b/clients/client-redshift/src/protocols/Aws_query.ts index 53ac2c3dcc644..bce68494007b1 100644 --- a/clients/client-redshift/src/protocols/Aws_query.ts +++ b/clients/client-redshift/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -8,7 +9,6 @@ import { expectUnion as __expectUnion, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseFloat as __strictParseFloat, @@ -22,7 +22,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AcceptReservedNodeExchangeCommandInput, @@ -19313,41 +19312,6 @@ const _i = "item"; const _m = "message"; const _me = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-rekognition/src/protocols/Aws_json1_1.ts b/clients/client-rekognition/src/protocols/Aws_json1_1.ts index 1e8a72ceb0b71..994c850bece59 100644 --- a/clients/client-rekognition/src/protocols/Aws_json1_1.ts +++ b/clients/client-rekognition/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -6290,54 +6291,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `RekognitionService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-rekognitionstreaming/src/protocols/Aws_restJson1.ts b/clients/client-rekognitionstreaming/src/protocols/Aws_restJson1.ts index 51dd6f72e8922..4ee328d6c196d 100644 --- a/clients/client-rekognitionstreaming/src/protocols/Aws_restJson1.ts +++ b/clients/client-rekognitionstreaming/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -655,54 +660,3 @@ const _xarslcv = "x-amz-rekognition-streaming-liveness-challenge-versions"; const _xarslsi = "x-amz-rekognition-streaming-liveness-session-id"; const _xarslvh = "x-amz-rekognition-streaming-liveness-video-height"; const _xarslvw = "x-amz-rekognition-streaming-liveness-video-width"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-repostspace/src/protocols/Aws_restJson1.ts b/clients/client-repostspace/src/protocols/Aws_restJson1.ts index 89847051de1ac..49476e2314bbd 100644 --- a/clients/client-repostspace/src/protocols/Aws_restJson1.ts +++ b/clients/client-repostspace/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -760,54 +761,3 @@ const _nT = "nextToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-resiliencehub/src/protocols/Aws_restJson1.ts b/clients/client-resiliencehub/src/protocols/Aws_restJson1.ts index b8c062592954e..7bd1ce7eb64a4 100644 --- a/clients/client-resiliencehub/src/protocols/Aws_restJson1.ts +++ b/clients/client-resiliencehub/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3504,54 +3505,3 @@ const _rTA = "recommendationTemplateArn"; const _s = "status"; const _tK = "tagKeys"; const _tLAT = "toLastAssessmentTime"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-resource-explorer-2/src/protocols/Aws_restJson1.ts b/clients/client-resource-explorer-2/src/protocols/Aws_restJson1.ts index 9a988e3bc5f5f..985a2136cd070 100644 --- a/clients/client-resource-explorer-2/src/protocols/Aws_restJson1.ts +++ b/clients/client-resource-explorer-2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1340,54 +1341,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-resource-groups-tagging-api/src/protocols/Aws_json1_1.ts b/clients/client-resource-groups-tagging-api/src/protocols/Aws_json1_1.ts index 11867b511acb6..31d2b11a587c1 100644 --- a/clients/client-resource-groups-tagging-api/src/protocols/Aws_json1_1.ts +++ b/clients/client-resource-groups-tagging-api/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -578,54 +579,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `ResourceGroupsTaggingAPI_20170126.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-resource-groups/src/protocols/Aws_restJson1.ts b/clients/client-resource-groups/src/protocols/Aws_restJson1.ts index 1eecb607df96e..26ac7a82cd306 100644 --- a/clients/client-resource-groups/src/protocols/Aws_restJson1.ts +++ b/clients/client-resource-groups/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1134,54 +1135,3 @@ const _MR = "MaxResults"; const _NT = "NextToken"; const _mR = "maxResults"; const _nT = "nextToken"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-robomaker/src/protocols/Aws_restJson1.ts b/clients/client-robomaker/src/protocols/Aws_restJson1.ts index 9595dc0ec4d17..aa69ac255f0cf 100644 --- a/clients/client-robomaker/src/protocols/Aws_restJson1.ts +++ b/clients/client-robomaker/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3833,54 +3834,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-rolesanywhere/src/protocols/Aws_restJson1.ts b/clients/client-rolesanywhere/src/protocols/Aws_restJson1.ts index 2f7d51c947475..fb112a9f5e228 100644 --- a/clients/client-rolesanywhere/src/protocols/Aws_restJson1.ts +++ b/clients/client-rolesanywhere/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1564,54 +1565,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _nT = "nextToken"; const _pS = "pageSize"; const _rA = "resourceArn"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-route-53-domains/src/protocols/Aws_json1_1.ts b/clients/client-route-53-domains/src/protocols/Aws_json1_1.ts index 5b5a62915e437..795fed27bebf7 100644 --- a/clients/client-route-53-domains/src/protocols/Aws_json1_1.ts +++ b/clients/client-route-53-domains/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1921,54 +1922,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Route53Domains_v20140515.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-route-53/package.json b/clients/client-route-53/package.json index fd01298770785..162e076a3fb9a 100644 --- a/clients/client-route-53/package.json +++ b/clients/client-route-53/package.json @@ -60,7 +60,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-route-53/src/protocols/Aws_restXml.ts b/clients/client-route-53/src/protocols/Aws_restXml.ts index cc37779673450..8214031eabd71 100644 --- a/clients/client-route-53/src/protocols/Aws_restXml.ts +++ b/clients/client-route-53/src/protocols/Aws_restXml.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestXmlErrorCode, parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { XmlNode as __XmlNode, XmlText as __XmlText } from "@aws-sdk/xml-builder"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; @@ -10,7 +11,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, map, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, @@ -25,7 +25,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { ActivateKeySigningKeyCommandInput, @@ -6773,47 +6772,3 @@ const _v = "vpcid"; const _ve = ''; const _ver = "version"; const _vp = "vpcregion"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - -const loadRestXmlErrorCode = (output: __HttpResponse, data: any): string | undefined => { - if (data.Error?.Code !== undefined) { - return data.Error.Code; - } - if (output.statusCode == 404) { - return "NotFound"; - } -}; diff --git a/clients/client-route53-recovery-cluster/src/protocols/Aws_json1_0.ts b/clients/client-route53-recovery-cluster/src/protocols/Aws_json1_0.ts index 3f171f9f95750..50b4cec6e77a9 100644 --- a/clients/client-route53-recovery-cluster/src/protocols/Aws_json1_0.ts +++ b/clients/client-route53-recovery-cluster/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -430,54 +431,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `ToggleCustomerAPI.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-route53-recovery-control-config/src/protocols/Aws_restJson1.ts b/clients/client-route53-recovery-control-config/src/protocols/Aws_restJson1.ts index 6738002847d12..bcf11da176cf0 100644 --- a/clients/client-route53-recovery-control-config/src/protocols/Aws_restJson1.ts +++ b/clients/client-route53-recovery-control-config/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1287,54 +1288,3 @@ const _CA = "ClusterArn"; const _MR = "MaxResults"; const _NT = "NextToken"; const _TK = "TagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-route53-recovery-readiness/src/protocols/Aws_restJson1.ts b/clients/client-route53-recovery-readiness/src/protocols/Aws_restJson1.ts index 439e8131c8bf4..f10a056662637 100644 --- a/clients/client-route53-recovery-readiness/src/protocols/Aws_restJson1.ts +++ b/clients/client-route53-recovery-readiness/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2013,54 +2014,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _rT = "resourceType"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-route53resolver/src/protocols/Aws_json1_1.ts b/clients/client-route53resolver/src/protocols/Aws_json1_1.ts index c5a3ef5f9c781..7cc4436370a57 100644 --- a/clients/client-route53resolver/src/protocols/Aws_json1_1.ts +++ b/clients/client-route53resolver/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3438,54 +3439,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Route53Resolver.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-rum/src/protocols/Aws_restJson1.ts b/clients/client-rum/src/protocols/Aws_restJson1.ts index 52d82d5987cbc..40b64725d2fb0 100644 --- a/clients/client-rum/src/protocols/Aws_restJson1.ts +++ b/clients/client-rum/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -1172,54 +1173,3 @@ const _nT = "nextToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-s3-control/package.json b/clients/client-s3-control/package.json index ad063262045b3..a890a113917a8 100644 --- a/clients/client-s3-control/package.json +++ b/clients/client-s3-control/package.json @@ -65,7 +65,6 @@ "@smithy/util-middleware": "^2.1.3", "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0", "uuid": "^9.0.1" }, diff --git a/clients/client-s3-control/src/protocols/Aws_restXml.ts b/clients/client-s3-control/src/protocols/Aws_restXml.ts index 438a3bf475587..2cdf4c87483b6 100644 --- a/clients/client-s3-control/src/protocols/Aws_restXml.ts +++ b/clients/client-s3-control/src/protocols/Aws_restXml.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestXmlErrorCode, parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { XmlNode as __XmlNode, XmlText as __XmlText } from "@aws-sdk/xml-builder"; import { requestBuilder as rb } from "@smithy/core"; import { @@ -15,7 +16,6 @@ import { expectUnion as __expectUnion, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, map, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, @@ -30,7 +30,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { v4 as generateIdempotencyToken } from "uuid"; import { @@ -10942,47 +10941,3 @@ const _xagw = "x-amz-grant-write"; const _xagwa = "x-amz-grant-write-acp"; const _xam = "x-amz-mfa"; const _xaoi = "x-amz-outpost-id"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - -const loadRestXmlErrorCode = (output: __HttpResponse, data: any): string | undefined => { - if (data.Error?.Code !== undefined) { - return data.Error.Code; - } - if (output.statusCode == 404) { - return "NotFound"; - } -}; diff --git a/clients/client-s3/package.json b/clients/client-s3/package.json index cf9cea83bccd5..2c43c383d31d4 100644 --- a/clients/client-s3/package.json +++ b/clients/client-s3/package.json @@ -79,7 +79,6 @@ "@smithy/util-stream": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-s3/src/protocols/Aws_restXml.ts b/clients/client-s3/src/protocols/Aws_restXml.ts index c0937548d8482..2e6eae7adc256 100644 --- a/clients/client-s3/src/protocols/Aws_restXml.ts +++ b/clients/client-s3/src/protocols/Aws_restXml.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestXmlErrorCode, parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { XmlNode as __XmlNode, XmlText as __XmlText } from "@aws-sdk/xml-builder"; import { requestBuilder as rb } from "@smithy/core"; import { @@ -16,7 +17,6 @@ import { expectUnion as __expectUnion, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, map, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, @@ -33,7 +33,6 @@ import { SdkStreamSerdeContext as __SdkStreamSerdeContext, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AbortMultipartUploadCommandInput, @@ -10349,47 +10348,3 @@ const _xatd = "x-amz-tagging-directive"; const _xavi = "x-amz-version-id"; const _xawrl = "x-amz-website-redirect-location"; const _xi = "x-id"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - -const loadRestXmlErrorCode = (output: __HttpResponse, data: any): string | undefined => { - if (data?.Code !== undefined) { - return data.Code; - } - if (output.statusCode == 404) { - return "NotFound"; - } -}; diff --git a/clients/client-s3outposts/src/protocols/Aws_restJson1.ts b/clients/client-s3outposts/src/protocols/Aws_restJson1.ts index c10064aa66673..7ea7bb6b8143b 100644 --- a/clients/client-s3outposts/src/protocols/Aws_restJson1.ts +++ b/clients/client-s3outposts/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -490,54 +491,3 @@ const _eI = "endpointId"; const _mR = "maxResults"; const _nT = "nextToken"; const _oI = "outpostId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sagemaker-a2i-runtime/src/protocols/Aws_restJson1.ts b/clients/client-sagemaker-a2i-runtime/src/protocols/Aws_restJson1.ts index cd24676c38583..a636b99e9c4b6 100644 --- a/clients/client-sagemaker-a2i-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-sagemaker-a2i-runtime/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -461,54 +462,3 @@ const _FDA = "FlowDefinitionArn"; const _MR = "MaxResults"; const _NT = "NextToken"; const _SO = "SortOrder"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sagemaker-edge/src/protocols/Aws_restJson1.ts b/clients/client-sagemaker-edge/src/protocols/Aws_restJson1.ts index a79f4b72cfd29..7d67a2570a575 100644 --- a/clients/client-sagemaker-edge/src/protocols/Aws_restJson1.ts +++ b/clients/client-sagemaker-edge/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -298,54 +299,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sagemaker-featurestore-runtime/src/protocols/Aws_restJson1.ts b/clients/client-sagemaker-featurestore-runtime/src/protocols/Aws_restJson1.ts index fc73284ac417e..fda8d06d0a34f 100644 --- a/clients/client-sagemaker-featurestore-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-sagemaker-featurestore-runtime/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -394,54 +395,3 @@ const _FN = "FeatureNames"; const _FNe = "FeatureName"; const _RIVAS = "RecordIdentifierValueAsString"; const _TS = "TargetStores"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sagemaker-geospatial/src/protocols/Aws_restJson1.ts b/clients/client-sagemaker-geospatial/src/protocols/Aws_restJson1.ts index 07cc205d9488b..3b51eb1b04a00 100644 --- a/clients/client-sagemaker-geospatial/src/protocols/Aws_restJson1.ts +++ b/clients/client-sagemaker-geospatial/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2148,54 +2153,3 @@ const _T = "Target"; const _TK = "TagKeys"; const _TRF = "TimeRangeFilter"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sagemaker-metrics/src/protocols/Aws_restJson1.ts b/clients/client-sagemaker-metrics/src/protocols/Aws_restJson1.ts index 77719fae7b61b..a9a9b9282f9a3 100644 --- a/clients/client-sagemaker-metrics/src/protocols/Aws_restJson1.ts +++ b/clients/client-sagemaker-metrics/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -128,54 +129,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts b/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts index d06aee0fc614a..b3ac0fc4406e8 100644 --- a/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-sagemaker-runtime/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -479,54 +480,3 @@ const _xasr = "x-amzn-sagemaker-requestttlseconds"; const _xastch = "x-amzn-sagemaker-target-container-hostname"; const _xastm = "x-amzn-sagemaker-target-model"; const _xastv = "x-amzn-sagemaker-target-variant"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sagemaker/src/protocols/Aws_json1_1.ts b/clients/client-sagemaker/src/protocols/Aws_json1_1.ts index b695e48b421b9..2aea19e95c2ed 100644 --- a/clients/client-sagemaker/src/protocols/Aws_json1_1.ts +++ b/clients/client-sagemaker/src/protocols/Aws_json1_1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -28800,54 +28805,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `SageMaker.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-savingsplans/src/protocols/Aws_restJson1.ts b/clients/client-savingsplans/src/protocols/Aws_restJson1.ts index 04e0ff441b1d7..7a9f1ea7a98b7 100644 --- a/clients/client-savingsplans/src/protocols/Aws_restJson1.ts +++ b/clients/client-savingsplans/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -698,54 +699,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-scheduler/src/protocols/Aws_restJson1.ts b/clients/client-scheduler/src/protocols/Aws_restJson1.ts index 7013f5e888a40..d195553c76c93 100644 --- a/clients/client-scheduler/src/protocols/Aws_restJson1.ts +++ b/clients/client-scheduler/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -930,54 +931,3 @@ const _SG = "ScheduleGroup"; const _TK = "TagKeys"; const _cT = "clientToken"; const _gN = "groupName"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-schemas/src/protocols/Aws_restJson1.ts b/clients/client-schemas/src/protocols/Aws_restJson1.ts index c9e8ee23e4dd7..7fdbb85bc4881 100644 --- a/clients/client-schemas/src/protocols/Aws_restJson1.ts +++ b/clients/client-schemas/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1837,54 +1838,3 @@ const _sNP = "schemaNamePrefix"; const _sV = "schemaVersion"; const _t = "type"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-secrets-manager/src/protocols/Aws_json1_1.ts b/clients/client-secrets-manager/src/protocols/Aws_json1_1.ts index 538ca6d53f004..c9125858f828e 100644 --- a/clients/client-secrets-manager/src/protocols/Aws_json1_1.ts +++ b/clients/client-secrets-manager/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1585,54 +1586,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `secretsmanager.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-securityhub/src/protocols/Aws_restJson1.ts b/clients/client-securityhub/src/protocols/Aws_restJson1.ts index b1f82d099e491..7fa67dc83172a 100644 --- a/clients/client-securityhub/src/protocols/Aws_restJson1.ts +++ b/clients/client-securityhub/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -10388,54 +10393,3 @@ const _SA = "StandardsArn"; const _SCI = "SecurityControlId"; const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-securitylake/src/protocols/Aws_restJson1.ts b/clients/client-securitylake/src/protocols/Aws_restJson1.ts index c0b5d3c573da1..f6bae9304d5de 100644 --- a/clients/client-securitylake/src/protocols/Aws_restJson1.ts +++ b/clients/client-securitylake/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1773,54 +1774,3 @@ const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _sV = "sourceVersion"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-serverlessapplicationrepository/src/protocols/Aws_restJson1.ts b/clients/client-serverlessapplicationrepository/src/protocols/Aws_restJson1.ts index 3ed20f5bd08f1..5a20934c7058a 100644 --- a/clients/client-serverlessapplicationrepository/src/protocols/Aws_restJson1.ts +++ b/clients/client-serverlessapplicationrepository/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1181,54 +1182,3 @@ const _SV = "SemanticVersion"; const _mI = "maxItems"; const _nT = "nextToken"; const _sV = "semanticVersion"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-service-catalog-appregistry/src/protocols/Aws_restJson1.ts b/clients/client-service-catalog-appregistry/src/protocols/Aws_restJson1.ts index 982a6028e81c3..89983598ff7f3 100644 --- a/clients/client-service-catalog-appregistry/src/protocols/Aws_restJson1.ts +++ b/clients/client-service-catalog-appregistry/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1416,54 +1417,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _rTS = "resourceTagStatus"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-service-catalog/src/protocols/Aws_json1_1.ts b/clients/client-service-catalog/src/protocols/Aws_json1_1.ts index 7661d0613f3f2..a15dfed001fe1 100644 --- a/clients/client-service-catalog/src/protocols/Aws_json1_1.ts +++ b/clients/client-service-catalog/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -5167,54 +5168,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWS242ServiceCatalogService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-service-quotas/src/protocols/Aws_json1_1.ts b/clients/client-service-quotas/src/protocols/Aws_json1_1.ts index 30b8a14305e09..316015c583bcd 100644 --- a/clients/client-service-quotas/src/protocols/Aws_json1_1.ts +++ b/clients/client-service-quotas/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1523,54 +1524,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `ServiceQuotasV20190624.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-servicediscovery/src/protocols/Aws_json1_1.ts b/clients/client-servicediscovery/src/protocols/Aws_json1_1.ts index a89eb9c6042f6..7a0bf677050f9 100644 --- a/clients/client-servicediscovery/src/protocols/Aws_json1_1.ts +++ b/clients/client-servicediscovery/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -1850,54 +1851,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Route53AutoNaming_v20170314.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ses/package.json b/clients/client-ses/package.json index c17b80ef58c85..cbc2308a13a8b 100644 --- a/clients/client-ses/package.json +++ b/clients/client-ses/package.json @@ -58,7 +58,6 @@ "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", "@smithy/util-waiter": "^2.1.3", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-ses/src/protocols/Aws_query.ts b/clients/client-ses/src/protocols/Aws_query.ts index 7de530ed77306..f91629b9c3237 100644 --- a/clients/client-ses/src/protocols/Aws_query.ts +++ b/clients/client-ses/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseFloat as __strictParseFloat, @@ -20,7 +20,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { CloneReceiptRuleSetCommandInput, @@ -8223,41 +8222,6 @@ const _e = "entry"; const _m = "message"; const _me = "member"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-sesv2/src/protocols/Aws_restJson1.ts b/clients/client-sesv2/src/protocols/Aws_restJson1.ts index 8c95a49eb088a..804d41ecdc9bb 100644 --- a/clients/client-sesv2/src/protocols/Aws_restJson1.ts +++ b/clients/client-sesv2/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -5485,54 +5486,3 @@ const _RA = "ResourceArn"; const _Re = "Reason"; const _SD = "StartDate"; const _TK = "TagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sfn/src/protocols/Aws_json1_0.ts b/clients/client-sfn/src/protocols/Aws_json1_0.ts index 6fe17685a0084..9b1eba1d39a07 100644 --- a/clients/client-sfn/src/protocols/Aws_json1_0.ts +++ b/clients/client-sfn/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -2767,54 +2768,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSStepFunctions.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-shield/src/protocols/Aws_json1_1.ts b/clients/client-shield/src/protocols/Aws_json1_1.ts index 24fcb81de9127..c08d364b4cbcc 100644 --- a/clients/client-shield/src/protocols/Aws_json1_1.ts +++ b/clients/client-shield/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2208,54 +2209,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSShield_20160616.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-signer/src/protocols/Aws_restJson1.ts b/clients/client-signer/src/protocols/Aws_restJson1.ts index 5c92f5b75d472..78a7393389e67 100644 --- a/clients/client-signer/src/protocols/Aws_restJson1.ts +++ b/clients/client-signer/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -1376,54 +1377,3 @@ const _sT = "signatureTimestamp"; const _st = "statuses"; const _t = "target"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-simspaceweaver/src/protocols/Aws_restJson1.ts b/clients/client-simspaceweaver/src/protocols/Aws_restJson1.ts index 4db9fc2842551..fc439136019a7 100644 --- a/clients/client-simspaceweaver/src/protocols/Aws_restJson1.ts +++ b/clients/client-simspaceweaver/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1008,54 +1009,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _s = "simulation"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sms/src/protocols/Aws_json1_1.ts b/clients/client-sms/src/protocols/Aws_json1_1.ts index 2536388c4eb2a..543a2134b5d84 100644 --- a/clients/client-sms/src/protocols/Aws_json1_1.ts +++ b/clients/client-sms/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2346,54 +2347,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSServerMigrationService_V2016_10_24.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-snow-device-management/src/protocols/Aws_restJson1.ts b/clients/client-snow-device-management/src/protocols/Aws_restJson1.ts index f0a23bb254d82..a8d0820891843 100644 --- a/clients/client-snow-device-management/src/protocols/Aws_restJson1.ts +++ b/clients/client-snow-device-management/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -920,54 +921,3 @@ const _s = "state"; const _t = "type"; const _tI = "taskId"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-snowball/src/protocols/Aws_json1_1.ts b/clients/client-snowball/src/protocols/Aws_json1_1.ts index 83db369c7fcb6..677ec78bdaf4a 100644 --- a/clients/client-snowball/src/protocols/Aws_json1_1.ts +++ b/clients/client-snowball/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1942,54 +1943,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSIESnowballJobManagementService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sns/package.json b/clients/client-sns/package.json index f5246a000af70..953d3c209220e 100644 --- a/clients/client-sns/package.json +++ b/clients/client-sns/package.json @@ -57,7 +57,6 @@ "@smithy/util-middleware": "^2.1.3", "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-sns/src/protocols/Aws_query.ts b/clients/client-sns/src/protocols/Aws_query.ts index 383b80a3c1407..3413d90110277 100644 --- a/clients/client-sns/src/protocols/Aws_query.ts +++ b/clients/client-sns/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -7,7 +8,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, withBaseException, @@ -18,7 +18,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AddPermissionCommandInput, AddPermissionCommandOutput } from "../commands/AddPermissionCommand"; import { @@ -4617,41 +4616,6 @@ const _nT = "nextToken"; const _pN = "phoneNumber"; const _pNh = "phoneNumbers"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-sqs/src/protocols/Aws_json1_0.ts b/clients/client-sqs/src/protocols/Aws_json1_0.ts index f5259f212fbb4..82c45913a8a3e 100644 --- a/clients/client-sqs/src/protocols/Aws_json1_0.ts +++ b/clients/client-sqs/src/protocols/Aws_json1_0.ts @@ -1,5 +1,12 @@ // smithy-typescript generated code -import { _toBool, _toNum, _toStr } from "@aws-sdk/core"; +import { + _toBool, + _toNum, + _toStr, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2070,57 +2077,6 @@ function sharedHeaders(operation: string): __HeaderBag { }; } -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; - const populateBodyWithQueryCompatibility = (parsedOutput: any, headers: __HeaderBag) => { const queryErrorHeader = headers["x-amzn-query-error"]; if (parsedOutput.body !== undefined && queryErrorHeader != null) { diff --git a/clients/client-ssm-contacts/src/protocols/Aws_json1_1.ts b/clients/client-ssm-contacts/src/protocols/Aws_json1_1.ts index 2148c12779134..7fbe9805c3bb8 100644 --- a/clients/client-ssm-contacts/src/protocols/Aws_json1_1.ts +++ b/clients/client-ssm-contacts/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2395,54 +2396,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `SSMContacts.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ssm-incidents/src/protocols/Aws_restJson1.ts b/clients/client-ssm-incidents/src/protocols/Aws_restJson1.ts index a07c9eb193780..b0cd60079c692 100644 --- a/clients/client-ssm-incidents/src/protocols/Aws_restJson1.ts +++ b/clients/client-ssm-incidents/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2114,54 +2119,3 @@ const _eI = "eventId"; const _iRA = "incidentRecordArn"; const _rA = "resourceArn"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ssm-sap/src/protocols/Aws_restJson1.ts b/clients/client-ssm-sap/src/protocols/Aws_restJson1.ts index 8629c14138c5d..34fba08b80fd1 100644 --- a/clients/client-ssm-sap/src/protocols/Aws_restJson1.ts +++ b/clients/client-ssm-sap/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1190,54 +1191,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-ssm/src/protocols/Aws_json1_1.ts b/clients/client-ssm/src/protocols/Aws_json1_1.ts index 4030cdf99f3c5..5002ca24f440e 100644 --- a/clients/client-ssm/src/protocols/Aws_json1_1.ts +++ b/clients/client-ssm/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -11768,54 +11769,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AmazonSSM.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sso-admin/src/protocols/Aws_json1_1.ts b/clients/client-sso-admin/src/protocols/Aws_json1_1.ts index 07b5f5777a7c3..3ed33d5fc687b 100644 --- a/clients/client-sso-admin/src/protocols/Aws_json1_1.ts +++ b/clients/client-sso-admin/src/protocols/Aws_json1_1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -3887,54 +3892,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `SWBExternalService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sso-oidc/src/protocols/Aws_restJson1.ts b/clients/client-sso-oidc/src/protocols/Aws_restJson1.ts index a5f19766c48e6..15ec1200e626d 100644 --- a/clients/client-sso-oidc/src/protocols/Aws_restJson1.ts +++ b/clients/client-sso-oidc/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -615,54 +616,3 @@ const isSerializableHeaderValue = (value: any): boolean => (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _ai = "aws_iam"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sso/src/protocols/Aws_restJson1.ts b/clients/client-sso/src/protocols/Aws_restJson1.ts index d4dbe81ffe9ac..b1e982828077f 100644 --- a/clients/client-sso/src/protocols/Aws_restJson1.ts +++ b/clients/client-sso/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -343,54 +344,3 @@ const _nt = "next_token"; const _rN = "roleName"; const _rn = "role_name"; const _xasbt = "x-amz-sso_bearer_token"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-storage-gateway/src/protocols/Aws_json1_1.ts b/clients/client-storage-gateway/src/protocols/Aws_json1_1.ts index c3ff41b1839d5..3621ac80c882f 100644 --- a/clients/client-storage-gateway/src/protocols/Aws_json1_1.ts +++ b/clients/client-storage-gateway/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4256,54 +4257,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `StorageGateway_20130630.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-sts/package.json b/clients/client-sts/package.json index 2ed27f8a7c5df..5513f86cc6b60 100644 --- a/clients/client-sts/package.json +++ b/clients/client-sts/package.json @@ -57,7 +57,6 @@ "@smithy/util-middleware": "^2.1.3", "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/clients/client-sts/src/protocols/Aws_query.ts b/clients/client-sts/src/protocols/Aws_query.ts index 9d10e65ef18b8..635c174fac693 100644 --- a/clients/client-sts/src/protocols/Aws_query.ts +++ b/clients/client-sts/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { collectBody, @@ -6,7 +7,6 @@ import { expectNonNull as __expectNonNull, expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, - getValueFromTextNode as __getValueFromTextNode, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, strictParseInt32 as __strictParseInt32, withBaseException, @@ -17,7 +17,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { AssumeRoleCommandInput, AssumeRoleCommandOutput } from "../commands/AssumeRoleCommand"; import { AssumeRoleWithSAMLCommandInput, AssumeRoleWithSAMLCommandOutput } from "../commands/AssumeRoleWithSAMLCommand"; @@ -1272,41 +1271,6 @@ const _WIT = "WebIdentityToken"; const _a = "arn"; const _m = "message"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/clients/client-supplychain/src/protocols/Aws_restJson1.ts b/clients/client-supplychain/src/protocols/Aws_restJson1.ts index cabf5ebc5bc0c..48cb25f4c3659 100644 --- a/clients/client-supplychain/src/protocols/Aws_restJson1.ts +++ b/clients/client-supplychain/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -315,54 +316,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-support-app/src/protocols/Aws_restJson1.ts b/clients/client-support-app/src/protocols/Aws_restJson1.ts index 5f4e49be2cacf..bac05083bc78a 100644 --- a/clients/client-support-app/src/protocols/Aws_restJson1.ts +++ b/clients/client-support-app/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -667,54 +668,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-support/src/protocols/Aws_json1_1.ts b/clients/client-support/src/protocols/Aws_json1_1.ts index 4cb078e1a4cfe..279246c2ecf04 100644 --- a/clients/client-support/src/protocols/Aws_json1_1.ts +++ b/clients/client-support/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1250,54 +1251,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSSupport_20130415.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-swf/src/protocols/Aws_json1_0.ts b/clients/client-swf/src/protocols/Aws_json1_0.ts index 2041b4feffba2..6852fe28985fa 100644 --- a/clients/client-swf/src/protocols/Aws_json1_0.ts +++ b/clients/client-swf/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2253,54 +2254,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `SimpleWorkflowService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-synthetics/src/protocols/Aws_restJson1.ts b/clients/client-synthetics/src/protocols/Aws_restJson1.ts index 3bdd606b9ff9c..595a532422219 100644 --- a/clients/client-synthetics/src/protocols/Aws_restJson1.ts +++ b/clients/client-synthetics/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1446,54 +1447,3 @@ const _DL = "DeleteLambda"; const _TK = "TagKeys"; const _dL = "deleteLambda"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-textract/src/protocols/Aws_json1_1.ts b/clients/client-textract/src/protocols/Aws_json1_1.ts index d39a60457e0a4..40e7fae44055d 100644 --- a/clients/client-textract/src/protocols/Aws_json1_1.ts +++ b/clients/client-textract/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2393,54 +2394,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Textract.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-timestream-query/src/protocols/Aws_json1_0.ts b/clients/client-timestream-query/src/protocols/Aws_json1_0.ts index ddae89849c5ec..f9b83b04f983f 100644 --- a/clients/client-timestream-query/src/protocols/Aws_json1_0.ts +++ b/clients/client-timestream-query/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1200,54 +1201,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Timestream_20181101.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-timestream-write/src/protocols/Aws_json1_0.ts b/clients/client-timestream-write/src/protocols/Aws_json1_0.ts index 8514d57f7df38..d4e013f882b76 100644 --- a/clients/client-timestream-write/src/protocols/Aws_json1_0.ts +++ b/clients/client-timestream-write/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1366,54 +1367,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Timestream_20181101.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-tnb/src/protocols/Aws_restJson1.ts b/clients/client-tnb/src/protocols/Aws_restJson1.ts index 3111fd6173811..be13975d1b591 100644 --- a/clients/client-tnb/src/protocols/Aws_restJson1.ts +++ b/clients/client-tnb/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2093,54 +2094,3 @@ const _mr = "max_results"; const _nT = "nextToken"; const _nom = "nextpage_opaque_marker"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-transcribe-streaming/src/protocols/Aws_restJson1.ts b/clients/client-transcribe-streaming/src/protocols/Aws_restJson1.ts index 008b3f2592321..7f37a76706841 100644 --- a/clients/client-transcribe-streaming/src/protocols/Aws_restJson1.ts +++ b/clients/client-transcribe-streaming/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1078,54 +1079,3 @@ const _xatvfn = "x-amzn-transcribe-vocabulary-filter-name"; const _xatvfn_ = "x-amzn-transcribe-vocabulary-filter-names"; const _xatvn = "x-amzn-transcribe-vocabulary-name"; const _xatvn_ = "x-amzn-transcribe-vocabulary-names"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-transcribe/src/protocols/Aws_json1_1.ts b/clients/client-transcribe/src/protocols/Aws_json1_1.ts index a0742f01dfc51..5a4428be7e7d6 100644 --- a/clients/client-transcribe/src/protocols/Aws_json1_1.ts +++ b/clients/client-transcribe/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2786,54 +2787,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `Transcribe.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-transfer/src/protocols/Aws_json1_1.ts b/clients/client-transfer/src/protocols/Aws_json1_1.ts index 8db25f093faa2..938ff3ed99f2f 100644 --- a/clients/client-transfer/src/protocols/Aws_json1_1.ts +++ b/clients/client-transfer/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2975,54 +2976,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `TransferService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-translate/src/protocols/Aws_json1_1.ts b/clients/client-translate/src/protocols/Aws_json1_1.ts index a35b0badd9a14..54ee6804c1413 100644 --- a/clients/client-translate/src/protocols/Aws_json1_1.ts +++ b/clients/client-translate/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1546,54 +1547,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSShineFrontendService_20170701.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-trustedadvisor/src/protocols/Aws_restJson1.ts b/clients/client-trustedadvisor/src/protocols/Aws_restJson1.ts index 48952e1124eaf..5b87a1a1cc996 100644 --- a/clients/client-trustedadvisor/src/protocols/Aws_restJson1.ts +++ b/clients/client-trustedadvisor/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -991,54 +992,3 @@ const _rC = "regionCode"; const _s = "source"; const _st = "status"; const _t = "type"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-verifiedpermissions/src/protocols/Aws_json1_0.ts b/clients/client-verifiedpermissions/src/protocols/Aws_json1_0.ts index 2a12b43a2f4b1..cf608c60caeaf 100644 --- a/clients/client-verifiedpermissions/src/protocols/Aws_json1_0.ts +++ b/clients/client-verifiedpermissions/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -1989,54 +1994,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `VerifiedPermissions.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-voice-id/src/protocols/Aws_json1_0.ts b/clients/client-voice-id/src/protocols/Aws_json1_0.ts index 7c3dc59ee4c6a..9087efe17f443 100644 --- a/clients/client-voice-id/src/protocols/Aws_json1_0.ts +++ b/clients/client-voice-id/src/protocols/Aws_json1_0.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -2006,54 +2007,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `VoiceID.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-vpc-lattice/src/protocols/Aws_restJson1.ts b/clients/client-vpc-lattice/src/protocols/Aws_restJson1.ts index 8c33e94418e36..e78585f65f36d 100644 --- a/clients/client-vpc-lattice/src/protocols/Aws_restJson1.ts +++ b/clients/client-vpc-lattice/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3081,54 +3086,3 @@ const _sNI = "serviceNetworkIdentifier"; const _tGT = "targetGroupType"; const _tK = "tagKeys"; const _vI = "vpcIdentifier"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-waf-regional/src/protocols/Aws_json1_1.ts b/clients/client-waf-regional/src/protocols/Aws_json1_1.ts index b1ec14c5cbfea..d6fc84bb953d8 100644 --- a/clients/client-waf-regional/src/protocols/Aws_json1_1.ts +++ b/clients/client-waf-regional/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4194,54 +4195,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSWAF_Regional_20161128.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-waf/src/protocols/Aws_json1_1.ts b/clients/client-waf/src/protocols/Aws_json1_1.ts index 55b36c41f7255..61e9a4b15b2f7 100644 --- a/clients/client-waf/src/protocols/Aws_json1_1.ts +++ b/clients/client-waf/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4008,54 +4009,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSWAF_20150824.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-wafv2/src/protocols/Aws_json1_1.ts b/clients/client-wafv2/src/protocols/Aws_json1_1.ts index a298751531c9d..2f26e8afc0229 100644 --- a/clients/client-wafv2/src/protocols/Aws_json1_1.ts +++ b/clients/client-wafv2/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4052,54 +4053,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `AWSWAF_20190729.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-wellarchitected/src/protocols/Aws_restJson1.ts b/clients/client-wellarchitected/src/protocols/Aws_restJson1.ts index 4b124e8ca5906..f1891fd285630 100644 --- a/clients/client-wellarchitected/src/protocols/Aws_restJson1.ts +++ b/clients/client-wellarchitected/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -4093,54 +4094,3 @@ const _TNP = "TemplateNamePrefix"; const _WI = "WorkloadId"; const _WNP = "WorkloadNamePrefix"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-wisdom/src/protocols/Aws_restJson1.ts b/clients/client-wisdom/src/protocols/Aws_restJson1.ts index 2e7a6028cdbf2..64f94795feecc 100644 --- a/clients/client-wisdom/src/protocols/Aws_restJson1.ts +++ b/clients/client-wisdom/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2487,54 +2492,3 @@ const _mR = "maxResults"; const _nT = "nextToken"; const _tK = "tagKeys"; const _wTS = "waitTimeSeconds"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-workdocs/src/protocols/Aws_restJson1.ts b/clients/client-workdocs/src/protocols/Aws_restJson1.ts index 877e7936b571c..73515351ba31f 100644 --- a/clients/client-workdocs/src/protocols/Aws_restJson1.ts +++ b/clients/client-workdocs/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3063,54 +3064,3 @@ const _uI = "userId"; const _uIs = "userIds"; const _v = "versionid"; const _vI = "versionId"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-worklink/src/protocols/Aws_restJson1.ts b/clients/client-worklink/src/protocols/Aws_restJson1.ts index 9804b492c0738..0864861f9958f 100644 --- a/clients/client-worklink/src/protocols/Aws_restJson1.ts +++ b/clients/client-worklink/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -1850,54 +1851,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _TK = "TagKeys"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-workmail/src/protocols/Aws_json1_1.ts b/clients/client-workmail/src/protocols/Aws_json1_1.ts index f0cf4101f33f3..b19907a5e4c23 100644 --- a/clients/client-workmail/src/protocols/Aws_json1_1.ts +++ b/clients/client-workmail/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4770,54 +4771,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `WorkMailService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-workmailmessageflow/src/protocols/Aws_restJson1.ts b/clients/client-workmailmessageflow/src/protocols/Aws_restJson1.ts index ec39f0e2f31dc..5c61cb4611008 100644 --- a/clients/client-workmailmessageflow/src/protocols/Aws_restJson1.ts +++ b/clients/client-workmailmessageflow/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -240,54 +241,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-workspaces-thin-client/src/protocols/Aws_restJson1.ts b/clients/client-workspaces-thin-client/src/protocols/Aws_restJson1.ts index 70a9b762e73fc..33eda412ec0f6 100644 --- a/clients/client-workspaces-thin-client/src/protocols/Aws_restJson1.ts +++ b/clients/client-workspaces-thin-client/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -1277,54 +1278,3 @@ const _nT = "nextToken"; const _rAS = "retryAfterSeconds"; const _ra = "retry-after"; const _tK = "tagKeys"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-workspaces-web/src/protocols/Aws_restJson1.ts b/clients/client-workspaces-web/src/protocols/Aws_restJson1.ts index e82ca7573dc5e..efd7f54c041dc 100644 --- a/clients/client-workspaces-web/src/protocols/Aws_restJson1.ts +++ b/clients/client-workspaces-web/src/protocols/Aws_restJson1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -3040,54 +3041,3 @@ const _tK = "tagKeys"; const _tSA = "trustStoreArn"; const _uALSA = "userAccessLoggingSettingsArn"; const _uSA = "userSettingsArn"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-workspaces/src/protocols/Aws_json1_1.ts b/clients/client-workspaces/src/protocols/Aws_json1_1.ts index 8da88006d1a43..c833c4052aa67 100644 --- a/clients/client-workspaces/src/protocols/Aws_json1_1.ts +++ b/clients/client-workspaces/src/protocols/Aws_json1_1.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { _json, @@ -4369,54 +4370,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `WorkspacesService.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/clients/client-xray/src/protocols/Aws_restJson1.ts b/clients/client-xray/src/protocols/Aws_restJson1.ts index cdbdfe7854fc3..81f8528cbf4d0 100644 --- a/clients/client-xray/src/protocols/Aws_restJson1.ts +++ b/clients/client-xray/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -2487,54 +2492,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java index 5452491dbaa85..8275f651fbcc6 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java @@ -108,18 +108,7 @@ static void generateDocumentBodyShapeSerde( */ static void generateJsonParseBody(GenerationContext context) { TypeScriptWriter writer = context.getWriter(); - - // Include a JSON body parser used to deserialize documents from HTTP responses. - writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES); - writer.openBlock("const parseBody = (streamBody: any, context: __SerdeContext): " - + "any => collectBodyString(streamBody, context).then(encoded => {", "});", () -> { - writer.openBlock("if (encoded.length) {", "}", () -> { - writer.write("return JSON.parse(encoded);"); - }); - writer.write("return {};"); - }); - - writer.write(""); + writer.addImport("parseJsonBody", "parseBody", AwsDependency.AWS_SDK_CORE); } static void generateJsonParseBodyWithQueryHeader(GenerationContext context) { @@ -137,17 +126,7 @@ static void generateJsonParseBodyWithQueryHeader(GenerationContext context) { */ static void generateJsonParseErrorBody(GenerationContext context) { TypeScriptWriter writer = context.getWriter(); - - // Include a JSON body parser used to deserialize documents from HTTP responses. - writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES); - writer.openBlock("const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {", - "}", () -> { - writer.write("const value = await parseBody(errorBody, context);"); - writer.write("value.message = value.message ?? value.Message;"); - writer.write("return value;"); - }); - - writer.write(""); + writer.addImport("parseJsonErrorBody", "parseErrorBody", AwsDependency.AWS_SDK_CORE); } /** @@ -158,36 +137,7 @@ static void generateJsonParseErrorBody(GenerationContext context) { */ static void generateXmlParseBody(GenerationContext context) { TypeScriptWriter writer = context.getWriter(); - - // Include an XML body parser used to deserialize documents from HTTP responses. - writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES); - writer.addImport("getValueFromTextNode", "__getValueFromTextNode", TypeScriptDependency.AWS_SMITHY_CLIENT); - writer.addDependency(TypeScriptDependency.XML_PARSER); - writer.addImport("XMLParser", null, TypeScriptDependency.XML_PARSER); - writer.openBlock("const parseBody = (streamBody: any, context: __SerdeContext): " - + "any => collectBodyString(streamBody, context).then(encoded => {", "});", () -> { - writer.openBlock("if (encoded.length) {", "}", () -> { - // Temporararily creating parser inside the function. - // Parser would be moved to runtime config in https://github.com/aws/aws-sdk-js-v3/issues/3979 - writer.write("const parser = new XMLParser({ attributeNamePrefix: '', htmlEntities: true, " - + "ignoreAttributes: false, ignoreDeclaration: true, parseTagValue: false, " - + "trimValues: false, tagValueProcessor: (_: any, val: any) => " - + "(val.trim() === '' && val.includes('\\n')) ? '': undefined });"); - writer.write("parser.addEntity('#xD', '\\r');"); - writer.write("parser.addEntity('#10', '\\n');"); - writer.write("const parsedObj = parser.parse(encoded);"); - writer.write("const textNodeName = '#text';"); - writer.write("const key = Object.keys(parsedObj)[0];"); - writer.write("const parsedObjToReturn = parsedObj[key];"); - writer.openBlock("if (parsedObjToReturn[textNodeName]) {", "}", () -> { - writer.write("parsedObjToReturn[key] = parsedObjToReturn[textNodeName];"); - writer.write("delete parsedObjToReturn[textNodeName];"); - }); - writer.write("return __getValueFromTextNode(parsedObjToReturn);"); - }); - writer.write("return {};"); - }); - writer.write(""); + writer.addImport("parseXmlBody", "parseBody", AwsDependency.AWS_SDK_CORE); } /** @@ -198,19 +148,7 @@ static void generateXmlParseBody(GenerationContext context) { */ static void generateXmlParseErrorBody(GenerationContext context) { TypeScriptWriter writer = context.getWriter(); - - // Include a JSON body parser used to deserialize documents from HTTP responses. - writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES); - writer.openBlock("const parseErrorBody = async (errorBody: any, context: __SerdeContext) => {", - "}", () -> { - writer.write("const value = await parseBody(errorBody, context);"); - writer.openBlock("if (value.Error) {", "}", () -> { - writer.write("value.Error.message = value.Error.message ?? value.Error.Message;"); - }); - writer.write("return value;"); - }); - - writer.write(""); + writer.addImport("parseXmlErrorBody", "parseErrorBody", AwsDependency.AWS_SDK_CORE); } /** diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java index 66b58f1cd31a0..e7532e5ace9d9 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java @@ -23,7 +23,6 @@ import software.amazon.smithy.aws.traits.ServiceTrait; import software.amazon.smithy.aws.traits.protocols.RestXmlTrait; import software.amazon.smithy.codegen.core.SymbolProvider; -import software.amazon.smithy.codegen.core.SymbolReference; import software.amazon.smithy.model.knowledge.HttpBinding; import software.amazon.smithy.model.knowledge.HttpBinding.Location; import software.amazon.smithy.model.shapes.MemberShape; @@ -110,24 +109,8 @@ public void generateSharedComponents(GenerationContext context) { TypeScriptWriter writer = context.getWriter(); writer.addDependency(AwsDependency.XML_BUILDER); - // Generate a function that handles the complex rules around deserializing - // an error code from a rest-xml error. - SymbolReference responseType = getApplicationProtocol().getResponseType(); - writer.openBlock("const loadRestXmlErrorCode = (\n" - + " output: $T,\n" - + " data: any\n" - + "): string | undefined => {", "};", responseType, () -> { - // Attempt to fetch the error code from the specific location. - String errorCodeCheckLocation = getErrorBodyLocation(context, "data") + "?.Code"; - String errorCodeAccessLocation = getErrorBodyLocation(context, "data") + ".Code"; - writer.openBlock("if ($L !== undefined) {", "}", errorCodeCheckLocation, () -> { - writer.write("return $L;", errorCodeAccessLocation); - }); + writer.addImport("loadRestXmlErrorCode", null, AwsDependency.AWS_SDK_CORE); - // Default a 404 status code to the NotFound code. - writer.openBlock("if (output.statusCode == 404) {", "}", () -> writer.write("return 'NotFound';")); - }); - writer.write(""); writer.write( context.getStringStore().flushVariableDeclarationCode() ); diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java index f2e2083ea36bc..2e3de03d09ed9 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java @@ -29,7 +29,6 @@ import software.amazon.smithy.typescript.codegen.TypeScriptWriter; import software.amazon.smithy.typescript.codegen.integration.DocumentMemberSerVisitor; import software.amazon.smithy.typescript.codegen.integration.HttpRpcProtocolGenerator; -import software.amazon.smithy.utils.IoUtils; import software.amazon.smithy.utils.SmithyInternalApi; /** @@ -107,7 +106,7 @@ public void generateSharedComponents(GenerationContext context) { TypeScriptWriter writer = context.getWriter(); writer.addUseImports(getApplicationProtocol().getResponseType()); - writer.write(IoUtils.readUtf8Resource(getClass(), "load-json-error-code-stub.ts")); + writer.addImport("loadRestJsonErrorCode", null, AwsDependency.AWS_SDK_CORE); if (context.getService().hasTrait(AwsQueryCompatibleTrait.class)) { AwsProtocolUtils.generateJsonParseBodyWithQueryHeader(context); diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java index f0fbb8d552b57..82e3777b01d2e 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/RestJsonProtocolGenerator.java @@ -38,7 +38,6 @@ import software.amazon.smithy.typescript.codegen.TypeScriptWriter; import software.amazon.smithy.typescript.codegen.integration.DocumentMemberSerVisitor; import software.amazon.smithy.typescript.codegen.integration.HttpBindingProtocolGenerator; -import software.amazon.smithy.utils.IoUtils; import software.amazon.smithy.utils.SmithyInternalApi; /** @@ -112,7 +111,7 @@ public void generateSharedComponents(GenerationContext context) { TypeScriptWriter writer = context.getWriter(); writer.addUseImports(getApplicationProtocol().getResponseType()); writer.addImport("take", null, TypeScriptDependency.AWS_SMITHY_CLIENT); - writer.write(IoUtils.readUtf8Resource(getClass(), "load-json-error-code-stub.ts")); + writer.addImport("loadRestJsonErrorCode", null, AwsDependency.AWS_SDK_CORE); writer.write( context.getStringStore().flushVariableDeclarationCode() diff --git a/packages/core/src/protocols/common.ts b/packages/core/src/protocols/common.ts new file mode 100644 index 0000000000000..d4efe45bd2657 --- /dev/null +++ b/packages/core/src/protocols/common.ts @@ -0,0 +1,5 @@ +import { collectBody } from "@smithy/smithy-client"; +import type { HttpResponse, SerdeContext } from "@smithy/types"; + +export const collectBodyString = (streamBody: any, context: SerdeContext): Promise => + collectBody(streamBody, context).then((body) => context.utf8Encoder(body)); diff --git a/packages/core/src/protocols/index.ts b/packages/core/src/protocols/index.ts index c3a1b7cf5d769..09a6ac214ca00 100644 --- a/packages/core/src/protocols/index.ts +++ b/packages/core/src/protocols/index.ts @@ -1,2 +1,4 @@ export * from "./coercing-serializers"; export * from "./json/awsExpectUnion"; +export * from "./json/parseJsonBody"; +export * from "./xml/parseXmlBody"; diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/load-json-error-code-stub.ts b/packages/core/src/protocols/json/parseJsonBody.ts similarity index 52% rename from codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/load-json-error-code-stub.ts rename to packages/core/src/protocols/json/parseJsonBody.ts index 1d3eaf5dac2b8..555627c7cb4a9 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/load-json-error-code-stub.ts +++ b/packages/core/src/protocols/json/parseJsonBody.ts @@ -1,7 +1,31 @@ -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { +import type { HttpResponse, SerdeContext } from "@smithy/types"; + +import { collectBodyString } from "../common"; + +export const parseJsonBody = (streamBody: any, context: SerdeContext): any => + collectBodyString(streamBody, context).then((encoded) => { + if (encoded.length) { + try { + return JSON.parse(encoded); + } catch (e: any) { + if (e?.name === "SyntaxError") { + Object.defineProperty(e, "$responseBodyText", { + value: encoded, + }); + } + throw e; + } + } + return {}; + }); + +export const parseJsonErrorBody = async (errorBody: any, context: SerdeContext) => { + const value = await parseJsonBody(errorBody, context); + value.message = value.message ?? value.Message; + return value; +}; + +export const loadRestJsonErrorCode = (output: HttpResponse, data: any): string | undefined => { const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); const sanitizeErrorCode = (rawValue: string | number): string => { diff --git a/packages/core/src/protocols/xml/parseXmlBody.ts b/packages/core/src/protocols/xml/parseXmlBody.ts new file mode 100644 index 0000000000000..ab12589469275 --- /dev/null +++ b/packages/core/src/protocols/xml/parseXmlBody.ts @@ -0,0 +1,64 @@ +import { getValueFromTextNode } from "@smithy/smithy-client"; +import type { HttpResponse, SerdeContext } from "@smithy/types"; +import { XMLParser } from "fast-xml-parser"; + +import { collectBodyString } from "../common"; + +export const parseXmlBody = (streamBody: any, context: SerdeContext): any => + collectBodyString(streamBody, context).then((encoded) => { + if (encoded.length) { + const parser = new XMLParser({ + attributeNamePrefix: "", + htmlEntities: true, + ignoreAttributes: false, + ignoreDeclaration: true, + parseTagValue: false, + trimValues: false, + tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), + }); + parser.addEntity("#xD", "\r"); + parser.addEntity("#10", "\n"); + + let parsedObj; + try { + parsedObj = parser.parse(encoded); + } catch (e: any) { + if (e && typeof e === "object") { + Object.defineProperty(e, "$responseBodyText", { + value: encoded, + }); + } + throw e; + } + + const textNodeName = "#text"; + const key = Object.keys(parsedObj)[0]; + const parsedObjToReturn = parsedObj[key]; + if (parsedObjToReturn[textNodeName]) { + parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; + delete parsedObjToReturn[textNodeName]; + } + return getValueFromTextNode(parsedObjToReturn); + } + return {}; + }); + +export const parseXmlErrorBody = async (errorBody: any, context: SerdeContext) => { + const value = await parseXmlBody(errorBody, context); + if (value.Error) { + value.Error.message = value.Error.message ?? value.Error.Message; + } + return value; +}; + +export const loadRestXmlErrorCode = (output: HttpResponse, data: any): string | undefined => { + if (data?.Error?.Code !== undefined) { + return data.Error.Code; + } + if (data?.Code !== undefined) { + return data.Code; + } + if (output.statusCode == 404) { + return "NotFound"; + } +}; diff --git a/private/aws-echo-service/src/protocols/Aws_restJson1.ts b/private/aws-echo-service/src/protocols/Aws_restJson1.ts index 40e228404a1e4..b1d455d3a1c8d 100644 --- a/private/aws-echo-service/src/protocols/Aws_restJson1.ts +++ b/private/aws-echo-service/src/protocols/Aws_restJson1.ts @@ -3,6 +3,7 @@ import { EchoCommandInput, EchoCommandOutput } from "../commands/EchoCommand"; import { LengthCommandInput, LengthCommandOutput } from "../commands/LengthCommand"; import { EchoServiceServiceException as __BaseException } from "../models/EchoServiceServiceException"; import { PalindromeException } from "../models/models_0"; +import { loadRestJsonErrorCode, parseJsonBody as parseBody, parseJsonErrorBody as parseErrorBody } from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; import { @@ -155,54 +156,3 @@ const isSerializableHeaderValue = (value: any): boolean => value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/private/aws-protocoltests-ec2/package.json b/private/aws-protocoltests-ec2/package.json index f547e9d28e511..ab4c9db03ab83 100644 --- a/private/aws-protocoltests-ec2/package.json +++ b/private/aws-protocoltests-ec2/package.json @@ -54,7 +54,6 @@ "@smithy/util-middleware": "^2.1.3", "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0", "uuid": "^9.0.1" }, diff --git a/private/aws-protocoltests-ec2/src/protocols/Aws_ec2.ts b/private/aws-protocoltests-ec2/src/protocols/Aws_ec2.ts index e2e0529d38ddc..ff2f5e70eaa1a 100644 --- a/private/aws-protocoltests-ec2/src/protocols/Aws_ec2.ts +++ b/private/aws-protocoltests-ec2/src/protocols/Aws_ec2.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -11,7 +12,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseEpochTimestamp as __parseEpochTimestamp, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, @@ -30,7 +30,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { v4 as generateIdempotencyToken } from "uuid"; import { DatetimeOffsetsCommandInput, DatetimeOffsetsCommandOutput } from "../commands/DatetimeOffsetsCommand"; @@ -2088,41 +2087,6 @@ const _tL = "timestampList"; const _v = "value"; const _va = "values"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts b/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts index df137bbfefeb3..2d479398f6889 100644 --- a/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts +++ b/private/aws-protocoltests-json-10/src/protocols/Aws_json1_0.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -945,54 +950,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `JsonRpc10.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts b/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts index a051d7057019f..c22d517a8eed1 100644 --- a/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts +++ b/private/aws-protocoltests-json/src/protocols/Aws_json1_1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -1218,54 +1223,3 @@ function sharedHeaders(operation: string): __HeaderBag { "x-amz-target": `JsonProtocol.${operation}`, }; } - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/private/aws-protocoltests-query/package.json b/private/aws-protocoltests-query/package.json index 9b0f650d4b743..746a1f6ddf6c0 100644 --- a/private/aws-protocoltests-query/package.json +++ b/private/aws-protocoltests-query/package.json @@ -54,7 +54,6 @@ "@smithy/util-middleware": "^2.1.3", "@smithy/util-retry": "^2.1.3", "@smithy/util-utf8": "^2.1.1", - "fast-xml-parser": "4.2.5", "tslib": "^2.5.0", "uuid": "^9.0.1" }, diff --git a/private/aws-protocoltests-query/src/protocols/Aws_query.ts b/private/aws-protocoltests-query/src/protocols/Aws_query.ts index 319083333d2bc..937baa4f7dbaa 100644 --- a/private/aws-protocoltests-query/src/protocols/Aws_query.ts +++ b/private/aws-protocoltests-query/src/protocols/Aws_query.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse, @@ -11,7 +12,6 @@ import { expectString as __expectString, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, parseBoolean as __parseBoolean, parseEpochTimestamp as __parseEpochTimestamp, parseRfc3339DateTimeWithOffset as __parseRfc3339DateTimeWithOffset, @@ -30,7 +30,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { v4 as generateIdempotencyToken } from "uuid"; import { DatetimeOffsetsCommandInput, DatetimeOffsetsCommandOutput } from "../commands/DatetimeOffsetsCommand"; @@ -2717,41 +2716,6 @@ const _tL = "timestampList"; const _v = "value"; const _va = "values"; -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - const buildFormUrlencodedString = (formEntries: Record): string => Object.entries(formEntries) .map(([key, value]) => __extendedEncodeURIComponent(key) + "=" + __extendedEncodeURIComponent(value)) diff --git a/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts b/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts index 34b5e54056995..aa52f81577de3 100644 --- a/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts +++ b/private/aws-protocoltests-restjson/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { requestBuilder as rb } from "@smithy/core"; import { HttpRequest as __HttpRequest, @@ -5078,54 +5083,3 @@ const _xt = "x-timestamplist"; const _xt_ = "x-targetepochseconds"; const _xt__ = "x-targethttpdate"; const _xt___ = "x-targetdatetime"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/private/aws-protocoltests-restxml/src/protocols/Aws_restXml.ts b/private/aws-protocoltests-restxml/src/protocols/Aws_restXml.ts index b598e8b3f36e5..1735f5665f53d 100644 --- a/private/aws-protocoltests-restxml/src/protocols/Aws_restXml.ts +++ b/private/aws-protocoltests-restxml/src/protocols/Aws_restXml.ts @@ -1,4 +1,5 @@ // smithy-typescript generated code +import { loadRestXmlErrorCode, parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core"; import { XmlNode as __XmlNode, XmlText as __XmlText } from "@aws-sdk/xml-builder"; import { requestBuilder as rb } from "@smithy/core"; import { @@ -17,7 +18,6 @@ import { expectUnion as __expectUnion, extendedEncodeURIComponent as __extendedEncodeURIComponent, getArrayIfSingleItem as __getArrayIfSingleItem, - getValueFromTextNode as __getValueFromTextNode, map, parseBoolean as __parseBoolean, parseEpochTimestamp as __parseEpochTimestamp, @@ -38,7 +38,6 @@ import { ResponseMetadata as __ResponseMetadata, SerdeContext as __SerdeContext, } from "@smithy/types"; -import { XMLParser } from "fast-xml-parser"; import { v4 as generateIdempotencyToken } from "uuid"; import { @@ -4619,47 +4618,3 @@ const _xt = "x-timestamplist"; const _xt_ = "x-targetepochseconds"; const _xt__ = "x-targethttpdate"; const _xt___ = "x-targetdatetime"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - const parser = new XMLParser({ - attributeNamePrefix: "", - htmlEntities: true, - ignoreAttributes: false, - ignoreDeclaration: true, - parseTagValue: false, - trimValues: false, - tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined), - }); - parser.addEntity("#xD", "\r"); - parser.addEntity("#10", "\n"); - const parsedObj = parser.parse(encoded); - const textNodeName = "#text"; - const key = Object.keys(parsedObj)[0]; - const parsedObjToReturn = parsedObj[key]; - if (parsedObjToReturn[textNodeName]) { - parsedObjToReturn[key] = parsedObjToReturn[textNodeName]; - delete parsedObjToReturn[textNodeName]; - } - return __getValueFromTextNode(parsedObjToReturn); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - if (value.Error) { - value.Error.message = value.Error.message ?? value.Error.Message; - } - return value; -}; - -const loadRestXmlErrorCode = (output: __HttpResponse, data: any): string | undefined => { - if (data.Error?.Code !== undefined) { - return data.Error.Code; - } - if (output.statusCode == 404) { - return "NotFound"; - } -}; diff --git a/private/aws-restjson-server/src/protocols/Aws_restJson1.ts b/private/aws-restjson-server/src/protocols/Aws_restJson1.ts index 7216b03b60d29..91b00e0aaebf3 100644 --- a/private/aws-restjson-server/src/protocols/Aws_restJson1.ts +++ b/private/aws-restjson-server/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { acceptMatches as __acceptMatches, NotAcceptableException as __NotAcceptableException, @@ -8441,54 +8446,3 @@ const _xt = "x-timestamplist"; const _xt_ = "x-targetepochseconds"; const _xt__ = "x-targethttpdate"; const _xt___ = "x-targetdatetime"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -}; diff --git a/private/aws-restjson-validation-server/src/protocols/Aws_restJson1.ts b/private/aws-restjson-validation-server/src/protocols/Aws_restJson1.ts index 31efac1f8745c..5e0842cc949ca 100644 --- a/private/aws-restjson-validation-server/src/protocols/Aws_restJson1.ts +++ b/private/aws-restjson-validation-server/src/protocols/Aws_restJson1.ts @@ -1,5 +1,10 @@ // smithy-typescript generated code -import { awsExpectUnion as __expectUnion } from "@aws-sdk/core"; +import { + awsExpectUnion as __expectUnion, + loadRestJsonErrorCode, + parseJsonBody as parseBody, + parseJsonErrorBody as parseErrorBody, +} from "@aws-sdk/core"; import { acceptMatches as __acceptMatches, NotAcceptableException as __NotAcceptableException, @@ -1549,54 +1554,3 @@ const isSerializableHeaderValue = (value: any): boolean => const _sIH = "stringInHeader"; const _sih = "string-in-headers"; - -const parseBody = (streamBody: any, context: __SerdeContext): any => - collectBodyString(streamBody, context).then((encoded) => { - if (encoded.length) { - return JSON.parse(encoded); - } - return {}; - }); - -const parseErrorBody = async (errorBody: any, context: __SerdeContext) => { - const value = await parseBody(errorBody, context); - value.message = value.message ?? value.Message; - return value; -}; - -/** - * Load an error code for the aws.rest-json-1.1 protocol. - */ -const loadRestJsonErrorCode = (output: __HttpResponse, data: any): string | undefined => { - const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); - - const sanitizeErrorCode = (rawValue: string | number): string => { - let cleanValue = rawValue; - if (typeof cleanValue === "number") { - cleanValue = cleanValue.toString(); - } - if (cleanValue.indexOf(",") >= 0) { - cleanValue = cleanValue.split(",")[0]; - } - if (cleanValue.indexOf(":") >= 0) { - cleanValue = cleanValue.split(":")[0]; - } - if (cleanValue.indexOf("#") >= 0) { - cleanValue = cleanValue.split("#")[1]; - } - return cleanValue; - }; - - const headerKey = findKey(output.headers, "x-amzn-errortype"); - if (headerKey !== undefined) { - return sanitizeErrorCode(output.headers[headerKey]); - } - - if (data.code !== undefined) { - return sanitizeErrorCode(data.code); - } - - if (data["__type"] !== undefined) { - return sanitizeErrorCode(data["__type"]); - } -};