Skip to content

Commit

Permalink
fix(Designer): Connection TestLink / TestRequest both require failure…
Browse files Browse the repository at this point in the history
… to show error (#4480)

Fixed issue with testLink / testRequest
  • Loading branch information
rllyy97 committed Mar 28, 2024
1 parent 6e07f84 commit b3e5ed2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */
import { SwaggerParser } from '../../../parsers';
import type { Connection, OpenAPIV2, Connector } from '../../../utils/src';
import type { Connection, OpenAPIV2, Connector, TestConnectionObject } from '../../../utils/src';
import {
ArgumentException,
isArmResourceId,
Expand Down Expand Up @@ -205,15 +205,28 @@ export abstract class BaseConnectionService implements IConnectionService {

protected async testConnection(connection: Connection): Promise<void> {
let response: HttpResponse<any> | undefined = undefined;
response = await this.requestTestConnection(connection);
if (response) this.handleTestConnectionResponse(response);
const testLink = connection.properties?.testLinks?.[0];
try {
if (testLink) {
response = await this.requestTestConnection(testLink);
if (response) this.handleTestConnectionResponse(response);
}
} catch (testLinkError: any) {
try {
const testRequest = connection.properties?.testRequests?.[0];
if (testRequest) {
response = await this.requestTestConnection(testRequest);
if (response) this.handleTestConnectionResponse(response);
}
} catch (testRequestError: any) {
throw testLinkError ?? testRequestError;
}
}
}

protected async requestTestConnection(connection: Connection): Promise<HttpResponse<any> | undefined> {
const testLinks = connection.properties?.testLinks;
const testRequests = connection.properties?.testRequests;
protected async requestTestConnection(testConnectionObj: TestConnectionObject): Promise<HttpResponse<any> | undefined> {
const { httpClient } = this.options;
const { method: httpMethod, requestUri: uri, body } = testRequests?.[0] ?? testLinks?.[0] ?? {};
const { method: httpMethod, requestUri: uri, body } = testConnectionObj;
if (!httpMethod || !uri) return;
const method = httpMethod.toUpperCase() as HTTP_METHODS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface ConnectionProperties {

export type Connection = ArmResource<ConnectionProperties>;

interface TestConnectionObject {
export interface TestConnectionObject {
body?: string;
method: string;
requestUri: string;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3e5ed2

Please sign in to comment.