Log the assembled S3 url if constructing a S3 client fails.

I was configuring an instance and didn't notice that I had pasted a space into the `endpoint` field. It was not obvious from the logs why the URL was invalid.
This commit is contained in:
Viv Lim 2023-07-24 20:34:37 -07:00
parent e35b38302d
commit 74179aafdf

View File

@ -11,17 +11,21 @@ export function getS3(meta: Meta) {
}` }`
: `${meta.objectStorageUseSSL ? "https://" : "http://"}example.net`; : `${meta.objectStorageUseSSL ? "https://" : "http://"}example.net`;
return new S3({ try {
endpoint: meta.objectStorageEndpoint || undefined, return new S3({
accessKeyId: meta.objectStorageAccessKey!, endpoint: meta.objectStorageEndpoint || undefined,
secretAccessKey: meta.objectStorageSecretKey!, accessKeyId: meta.objectStorageAccessKey!,
region: meta.objectStorageRegion || undefined, secretAccessKey: meta.objectStorageSecretKey!,
sslEnabled: meta.objectStorageUseSSL, region: meta.objectStorageRegion || undefined,
s3ForcePathStyle: !meta.objectStorageEndpoint // AWS with endPoint omitted sslEnabled: meta.objectStorageUseSSL,
? false s3ForcePathStyle: !meta.objectStorageEndpoint // AWS with endPoint omitted
: meta.objectStorageS3ForcePathStyle, ? false
httpOptions: { : meta.objectStorageS3ForcePathStyle,
agent: getAgentByUrl(new URL(u), !meta.objectStorageUseProxy), httpOptions: {
}, agent: getAgentByUrl(new URL(u), !meta.objectStorageUseProxy),
}); },
});
} catch (e) {
throw new Error(`Failed to construct S3 client, assembled S3 URL: ${u}\n${e}`);
}
} }