Skip to content

Commit

Permalink
chore: use optional chaining (smithy-lang#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored and srchase committed Jun 16, 2023
1 parent 8dddece commit bef2242
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/fetch-http-handler/src/fetch-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export class FetchHttpHandler implements HttpHandler {
request: HttpRequest,
options: HttpHandlerOptions
): Promise<{ response: HttpResponse }> {
const abortSignal = options && options.abortSignal;
const abortSignal = options?.abortSignal;
const requestTimeoutInMs = this.httpOptions.requestTimeout;

// if the request was already aborted, prevent doing extra work
if (abortSignal && abortSignal.aborted) {
if (abortSignal?.aborted) {
const abortError = new Error("Request aborted");
abortError.name = "AbortError";
return Promise.reject(abortError);
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-retry/src/retryDecider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export const defaultRetryDecider = (error: SdkError) => {
};

function hasMetadata(error: any): error is MetadataBearer {
return error && error.$metadata;
return error?.$metadata;
}
2 changes: 1 addition & 1 deletion packages/middleware-stack/src/MiddlewareStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class MiddlewareStack<Input extends object, Output extends object> {
: defaultAnchorValue;
let relativeEntry = prev;
//reverse relative entry linked list and add to ordered handler list
while (relativeEntry && relativeEntry.prev) {
while (relativeEntry?.prev) {
relativeEntry = relativeEntry.prev;
}
while (relativeEntry) {
Expand Down
2 changes: 1 addition & 1 deletion packages/node-http-handler/src/node-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class NodeHttpHandler implements HttpHandler {
): Promise<{ response: HttpResponse }> {
return new Promise((resolve, reject) => {
// if the request was already aborted, prevent doing extra work
if (abortSignal && abortSignal.aborted) {
if (abortSignal?.aborted) {
const abortError = new Error("Request aborted");
abortError.name = "AbortError";
reject(abortError);
Expand Down
2 changes: 1 addition & 1 deletion packages/node-http-handler/src/node-http2-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class NodeHttp2Handler implements HttpHandler {
): Promise<{ response: HttpResponse }> {
return new Promise((resolve, reject) => {
// if the request was already aborted, prevent doing extra work
if (abortSignal && abortSignal.aborted) {
if (abortSignal?.aborted) {
const abortError = new Error("Request aborted");
abortError.name = "AbortError";
reject(abortError);
Expand Down
2 changes: 1 addition & 1 deletion packages/property-provider/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function chain<T>(...providers: Array<Provider<T>>): Provider<T> {
);
for (const provider of providers) {
promise = promise.catch((err: any) => {
if (err && err.tryNextLink) {
if (err?.tryNextLink) {
return provider();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/signature-v4/src/getCanonicalHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getCanonicalHeaders(
const canonicalHeaderName = headerName.toLowerCase();
if (
canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS ||
(unsignableHeaders && unsignableHeaders.has(canonicalHeaderName)) ||
unsignableHeaders?.has(canonicalHeaderName) ||
PROXY_HEADER_PATTERN.test(canonicalHeaderName) ||
SEC_HEADER_PATTERN.test(canonicalHeaderName)
) {
Expand Down

0 comments on commit bef2242

Please sign in to comment.