Skip to content

Commit f58afc2

Browse files
cleanup tests
1 parent 00e4389 commit f58afc2

22 files changed

+918
-949
lines changed

LICENCE renamed to LICENSE

File renamed without changes.

build/smithy/source/model/model.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/smithy/source/sources/cloudserver.smithy

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/smithy/source/sources/deleteBucketIndexes.smithy

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/smithy/source/typescript-codegen/yarn.lock

Lines changed: 197 additions & 197 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CloudserverClient as GeneratedCloudserverClient, CloudserverClientConfig } from '../build/smithy/source/typescript-codegen';
22
export * from '../build/smithy/source/typescript-codegen';
3+
export * from './utils';
34
export declare class CloudserverClient extends GeneratedCloudserverClient {
45
constructor(config: CloudserverClientConfig);
5-
private createCustomErrorMiddleware;
66
}

dist/index.js

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
1515
};
1616
Object.defineProperty(exports, "__esModule", { value: true });
1717
exports.CloudserverClient = void 0;
18-
const fast_xml_parser_1 = require("fast-xml-parser");
1918
const typescript_codegen_1 = require("../build/smithy/source/typescript-codegen");
19+
const utils_1 = require("./utils");
2020
__exportStar(require("../build/smithy/source/typescript-codegen"), exports);
21+
__exportStar(require("./utils"), exports);
2122
class CloudserverClient extends typescript_codegen_1.CloudserverClient {
2223
constructor(config) {
2324
super(config);
24-
this.createCustomErrorMiddleware = () => {
25-
return (next) => async (args) => {
26-
const parseXmlError = (xml) => {
27-
try {
28-
const result = new fast_xml_parser_1.XMLParser({}).parse(xml);
29-
return {
30-
code: result.Error?.Code,
31-
message: result.Error?.Message,
32-
requestId: result.Error?.RequestId,
33-
};
34-
}
35-
catch (parseError) {
36-
return {
37-
code: null,
38-
message: 'Malformed XML error response',
39-
requestId: null,
40-
};
41-
}
42-
};
43-
try {
44-
return await next(args);
45-
}
46-
catch (error) {
47-
const response = error.$response;
48-
const statusCode = error.$metadata?.httpStatusCode;
49-
const headers = response?.headers || {};
50-
const contentType = (headers['content-type'] || '').toLowerCase();
51-
if (contentType.includes('application/xml') || contentType.includes('text/xml')) {
52-
const body = response?.body;
53-
const xml = body?.toString() || '';
54-
const errorInfo = parseXmlError(xml);
55-
const xmlError = new typescript_codegen_1.CloudserverServiceException({
56-
name: errorInfo.code || error.name,
57-
message: errorInfo.message || 'XML error response',
58-
$fault: statusCode >= 500 ? 'server' : 'client',
59-
$metadata: error.$metadata || {},
60-
$response: error.$response,
61-
});
62-
xmlError.parsedXml = errorInfo;
63-
throw xmlError;
64-
}
65-
const s3cNginxProxyResponse = contentType.includes('text/html');
66-
if (s3cNginxProxyResponse) {
67-
const body = response?.body;
68-
const html = body?.toString() || '';
69-
const title = html.match(/<title[^>]*>([^<]+)<\/title>/i);
70-
const message = title && title[1] || 'HTML error response';
71-
const htmlError = new typescript_codegen_1.CloudserverServiceException({
72-
name: `HTML ${response?.reason || 'Error'}`,
73-
message: message,
74-
$fault: statusCode >= 500 ? 'server' : 'client',
75-
$metadata: error.$metadata || {},
76-
$response: error.$response,
77-
});
78-
htmlError.rawBody = html;
79-
throw htmlError;
80-
}
81-
throw error;
82-
}
83-
};
84-
};
85-
this.middlewareStack.add(this.createCustomErrorMiddleware(), {
25+
this.middlewareStack.add((0, utils_1.createCustomErrorMiddleware)(), {
8626
step: 'deserialize',
8727
name: 'cloudserverErrorHandler'
8828
});

dist/utils.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Adds middleware to manually set the Content-Length header on a command.
3+
*
4+
* This is useful when streaming data where the SDK cannot automatically determine
5+
* the content length, preventing it from falling back to chunked transfer encoding.
6+
*
7+
* @param command - The command to add middleware to
8+
* @param contentLength - The content length value (number or string)
9+
*/
10+
export declare function addContentLengthMiddleware<TCommand>(command: TCommand, contentLength: number | string | undefined): void;
11+
export declare function createCustomErrorMiddleware(): (next: any) => (args: any) => Promise<any>;

dist/utils.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.addContentLengthMiddleware = addContentLengthMiddleware;
4+
exports.createCustomErrorMiddleware = createCustomErrorMiddleware;
5+
const fast_xml_parser_1 = require("fast-xml-parser");
6+
const typescript_codegen_1 = require("../build/smithy/source/typescript-codegen");
7+
/**
8+
* Adds middleware to manually set the Content-Length header on a command.
9+
*
10+
* This is useful when streaming data where the SDK cannot automatically determine
11+
* the content length, preventing it from falling back to chunked transfer encoding.
12+
*
13+
* @param command - The command to add middleware to
14+
* @param contentLength - The content length value (number or string)
15+
*/
16+
function addContentLengthMiddleware(command, contentLength) {
17+
if (!contentLength) {
18+
return;
19+
}
20+
const commandWithMiddleware = command;
21+
if (!commandWithMiddleware.middlewareStack) {
22+
throw new Error('Command does not have a middleware stack');
23+
}
24+
commandWithMiddleware.middlewareStack.add((next) => async (args) => {
25+
const request = args.request;
26+
if (request && request.headers) {
27+
request.headers['content-length'] = String(contentLength);
28+
}
29+
return next(args);
30+
}, { step: 'build', priority: 'high' });
31+
return;
32+
}
33+
function createCustomErrorMiddleware() {
34+
return (next) => async (args) => {
35+
const parseXmlError = (xml) => {
36+
try {
37+
const result = new fast_xml_parser_1.XMLParser({}).parse(xml);
38+
return {
39+
code: result.Error?.Code,
40+
message: result.Error?.Message,
41+
requestId: result.Error?.RequestId,
42+
};
43+
}
44+
catch (parseError) {
45+
return {
46+
code: null,
47+
message: 'Malformed XML error response',
48+
requestId: null,
49+
};
50+
}
51+
};
52+
try {
53+
return await next(args);
54+
}
55+
catch (error) {
56+
const response = error.$response;
57+
const statusCode = error.$metadata?.httpStatusCode;
58+
const headers = response?.headers || {};
59+
const contentType = (headers['content-type'] || '').toLowerCase();
60+
if (contentType.includes('application/xml') || contentType.includes('text/xml')) {
61+
const body = response?.body;
62+
const xml = body?.toString() || '';
63+
const errorInfo = parseXmlError(xml);
64+
const xmlError = new typescript_codegen_1.CloudserverServiceException({
65+
name: errorInfo.code || error.name,
66+
message: errorInfo.message || 'XML error response',
67+
$fault: statusCode >= 500 ? 'server' : 'client',
68+
$metadata: error.$metadata || {},
69+
$response: error.$response,
70+
});
71+
xmlError.parsedXml = errorInfo;
72+
throw xmlError;
73+
}
74+
const s3cNginxProxyResponse = contentType.includes('text/html');
75+
if (s3cNginxProxyResponse) {
76+
const body = response?.body;
77+
const html = body?.toString() || '';
78+
const title = html.match(/<title[^>]*>([^<]+)<\/title>/i);
79+
const message = title && title[1] || 'HTML error response';
80+
const htmlError = new typescript_codegen_1.CloudserverServiceException({
81+
name: `HTML ${response?.reason || 'Error'}`,
82+
message: message,
83+
$fault: statusCode >= 500 ? 'server' : 'client',
84+
$metadata: error.$metadata || {},
85+
$response: error.$response,
86+
});
87+
htmlError.rawBody = html;
88+
throw htmlError;
89+
}
90+
throw error;
91+
}
92+
};
93+
}

models/deleteBucketIndexes.smithy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ $version: "2.0"
22
namespace cloudserver.client
33

44
@http(method: "POST", uri: "/_/backbeat/index/{Bucket}?operation=delete")
5+
@idempotent
56
operation DeleteBucketIndexes {
67
input: DeleteBucketIndexesInput,
78
output: DeleteBucketIndexesOutput

0 commit comments

Comments
 (0)