Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// It's likely that the refresh token has expired, so
// return null so that the credential implementation will
// initiate the authentication flow again.
logger.info(`IdentityClient: interaction required for client ID: ${clientId}`);
span.setStatus({
code: CanonicalCode.UNAUTHENTICATED,
message: err.message
});
return null;
} else {
logger.warning(
`IdentityClient: failed refreshing token for client ID: ${clientId}: ${err}`
);
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
}
} finally {
span.end();
}
}
export function handleInvalidQuery(
this: pgTypes.Client & PgClientExtended,
tracer: Tracer,
originalQuery: typeof pgTypes.Client.prototype.query,
...args: unknown[]
) {
let result;
const span = pgStartSpan(tracer, this, PostgresPlugin.BASE_SPAN_NAME);
try {
result = originalQuery.apply(this, args as never);
span.setStatus({ code: CanonicalCode.OK }); // this will never happen, but set a status anyways
} catch (e) {
span.setStatus({ code: CanonicalCode.UNKNOWN, message: e.message });
throw e;
} finally {
span.end();
}
return result;
}
export async function trace(fn: () => Promise, span: Span): Promise {
try {
await fn();
span.setStatus({ code: CanonicalCode.OK });
} catch (err) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
} finally {
span.end();
}
}
const endSpan = (span: Span, err?: Error | null) => {
if (err) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message,
});
} else {
span.setStatus({ code: CanonicalCode.OK });
}
span.end();
};
} else if (isEventDataBatch(eventData)) {
spanContextsToLink = eventData._messageSpanContexts;
}
const sendSpan = this._createSendSpan(getParentSpan(options), spanContextsToLink);
try {
const result = await this._eventHubSender!.send(eventData, {
...this._senderOptions,
...options
});
sendSpan.setStatus({ code: CanonicalCode.OK });
return result;
} catch (err) {
sendSpan.setStatus({
code: CanonicalCode.UNKNOWN,
message: err.message
});
throw err;
} finally {
sendSpan.end();
}
}
}),
headers: {
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
abortSignal: options && options.abortSignal,
spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions
});
const tokenResponse = await this.identityClient.sendTokenRequest(webResource);
return (tokenResponse && tokenResponse.accessToken) || null;
} catch (err) {
const code =
err.name === AuthenticationErrorName
? CanonicalCode.UNAUTHENTICATED
: CanonicalCode.UNKNOWN;
span.setStatus({
code,
message: err.message
});
throw err;
} finally {
span.end();
}
}
}
spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions
});
logger.info("DeviceCodeCredential: sending devicecode request");
const response = await this.identityClient.sendRequest(webResource);
if (!(response.status === 200 || response.status === 201)) {
throw new AuthenticationError(response.status, response.bodyAsText);
}
return response.parsedBody as DeviceCodeResponse;
} catch (err) {
const code =
err.name === AuthenticationErrorName
? CanonicalCode.UNAUTHENTICATED
: CanonicalCode.UNKNOWN;
if (err.name === AuthenticationErrorName) {
logger.warning(
`DeviceCodeCredential: failed to authenticate ${
(err as AuthenticationError).errorResponse.errorDescription
}`
);
} else {
logger.warning(`DeviceCodeCredential: failed to authenticate ${err}`);
}
span.setStatus({
code,
message: err.message
});
throw err;
export const _grpcStatusCodeToCanonicalCode = (
status?: grpcTypes.status
): CanonicalCode => {
if (status !== 0 && !status) {
return CanonicalCode.UNKNOWN;
}
return status as number;
};
static getCanonicalCode(err: Error) {
if (Spanner.isRestError(err)) {
switch (err.statusCode) {
case 401:
return CanonicalCode.PERMISSION_DENIED;
case 404:
return CanonicalCode.NOT_FOUND;
case 412:
return CanonicalCode.FAILED_PRECONDITION;
}
}
return CanonicalCode.UNKNOWN;
}