Skip to content

Commit

Permalink
Merge pull request #373 from ballerina-platform/patch-8.0.x
Browse files Browse the repository at this point in the history
Improve error message for client configuration failures
  • Loading branch information
NipunaRanasinghe authored Nov 21, 2024
2 parents 9fed2a4 + 28b108b commit 28bf740
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
call_stdlib_workflow:
name: Run StdLib Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-connector-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-connector-template.yml@2201.10.x
secrets: inherit
with:
additional-build-flags: "-x :salesforce-examples:build"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
call_workflow:
name: Run Connector Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/build-connector-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-connector-template.yml@2201.10.x
secrets: inherit
with:
repo-name: module-ballerinax-salesforce
2 changes: 1 addition & 1 deletion .github/workflows/daily-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
call_workflow:
name: Run Daily Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/daily-build-connector-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/daily-build-connector-template.yml@2201.10.x
secrets: inherit
with:
repo-name: module-ballerinax-salesforce
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dev-stg-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
call_workflow:
name: Run Dev\Stage Central Publish Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/dev-stage-central-publish-connector-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/dev-stage-central-publish-connector-template.yml@2201.10.x
secrets: inherit
with:
environment: ${{ github.event.inputs.environment }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
call_workflow:
name: Run PR Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/pr-build-connector-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/pr-build-connector-template.yml@2201.10.x
secrets: inherit

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
call_workflow:
name: Run Release Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/release-package-connector-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/release-package-connector-template.yml@2201.10.x
secrets: inherit
with:
package-name: salesforce
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
call_workflow:
name: Run Trivy Scan Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@2201.10.x
secrets: inherit
with:
additional-build-flags: "-x :salesforce-examples:build -Pgroups=mock"
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
distribution = "2201.8.0"
org = "ballerinax"
name = "salesforce"
version = "8.0.2"
version = "8.0.3"
export = ["salesforce", "salesforce.bulk", "salesforce.soap"]
license= ["Apache-2.0"]
authors = ["Ballerina"]
Expand All @@ -17,10 +17,10 @@ observabilityIncluded = true
graalvmCompatible = true

[[platform.java17.dependency]]
path = "../native/build/libs/salesforce-native-8.0.2.jar"
path = "../native/build/libs/salesforce-native-8.0.3-SNAPSHOT.jar"
groupId = "io.ballerinax"
artifactId = "salesforce"
version = "8.0.2"
version = "8.0.3-SNAPSHOT"

[[platform.java17.dependency]]
groupId = "com.opencsv"
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.10.13"
version = "2.10.17"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -93,7 +93,7 @@ modules = [
[[package]]
org = "ballerina"
name = "io"
version = "1.6.0"
version = "1.6.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand Down Expand Up @@ -377,7 +377,7 @@ modules = [
[[package]]
org = "ballerinax"
name = "salesforce"
version = "8.0.2"
version = "8.0.3"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public isolated client class Client {
# + salesforceConfig - Salesforce Connector configuration
# + return - `sfdc:Error` on failure of initialization or else `()`
public isolated function init(ConnectionConfig config) returns error? {
http:Client|http:ClientError|error httpClientResult;
http:Client|http:ClientError httpClientResult;
http:ClientConfiguration httpClientConfig = check config:constructHTTPClientConfig(config);
httpClientResult = trap new (config.baseUrl, httpClientConfig);
httpClientResult = new (config.baseUrl, httpClientConfig);

if httpClientResult is http:Client {
self.salesforceClient = httpClientResult;
} else {
return error(INVALID_CLIENT_CONFIG);
return error(CLIENT_INIT_ERROR_MSG + httpClientResult.message(), httpClientResult);
}
}

Expand Down
3 changes: 1 addition & 2 deletions ballerina/errors.bal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ const STATUS_CODE = "statusCode";
const HEADERS = "headers";
const BODY = "body";


public const string CLIENT_INIT_ERROR_MSG = "Error occurred while initializing the client: ";
public const string ERR_EXTRACTING_ERROR_MSG = "Error occured while extracting errors from payload.";
public const string INVALID_CLIENT_CONFIG = "Invalid values provided for client configuration parameters.";
24 changes: 10 additions & 14 deletions ballerina/modules/bulk/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,26 @@ public isolated client class Client {
# + return - An error on failure of initialization or else `()`
public isolated function init(ConnectionConfig config) returns error? {
http:ClientConfiguration httpClientConfig = check config:constructHTTPClientConfig(config);
http:OAuth2RefreshTokenGrantConfig|http:BearerTokenConfig auth = let var authConfig = config.auth in
(authConfig is http:BearerTokenConfig ? authConfig : {...authConfig});
http:OAuth2RefreshTokenGrantConfig|http:BearerTokenConfig auth = let var authConfig = config.auth in
(authConfig is http:BearerTokenConfig ? authConfig : {...authConfig});
self.clientConfig = auth.cloneReadOnly();

http:ClientOAuth2Handler|http:ClientBearerTokenAuthHandler|error httpHandlerResult;
if auth is http:OAuth2RefreshTokenGrantConfig {
httpHandlerResult = trap new http:ClientOAuth2Handler(auth);
} else {
httpHandlerResult = trap new http:ClientBearerTokenAuthHandler(auth);
}
http:ClientOAuth2Handler|http:ClientBearerTokenAuthHandler httpHandlerResult;

if httpHandlerResult is http:ClientOAuth2Handler|http:ClientBearerTokenAuthHandler {
self.clientHandler = httpHandlerResult;
if auth is http:OAuth2RefreshTokenGrantConfig {
httpHandlerResult = new http:ClientOAuth2Handler(auth);
} else {
return error(INVALID_CLIENT_CONFIG);
httpHandlerResult = new http:ClientBearerTokenAuthHandler(auth);
}
self.clientHandler = httpHandlerResult;

http:Client|http:ClientError|error httpClientResult;
httpClientResult = trap new (config.baseUrl, httpClientConfig);
http:Client|http:ClientError httpClientResult;
httpClientResult = new (config.baseUrl, httpClientConfig);

if httpClientResult is http:Client {
self.salesforceClient = httpClientResult;
} else {
return error(INVALID_CLIENT_CONFIG);
return error(utils:CLIENT_INIT_ERROR_MSG + httpClientResult.message(), httpClientResult);
}
}

Expand Down
3 changes: 1 addition & 2 deletions ballerina/modules/bulk/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ const string FORWARD_SLASH = "/";
# Constant field `JSON_STATE_CLOSED_PAYLOAD`. Holds the value of JSON body which needs to close the job.
final json JSON_STATE_CLOSED_PAYLOAD = {state: "Closed"};

public const string ERR_EXTRACTING_ERROR_MSG = "Error occured while extracting errors from payload.";
public const INVALID_CLIENT_CONFIG = "Invalid values provided for client configuration parameters.";
public const string ERR_EXTRACTING_ERROR_MSG = "Error occurred while extracting errors from payload.";
21 changes: 8 additions & 13 deletions ballerina/modules/soap/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,24 @@ public isolated client class Client {
# + return - An error on failure of initialization or else `()`
public isolated function init(ConnectionConfig config) returns error? {
http:ClientConfiguration httpClientConfig = check config:constructHTTPClientConfig(config);
http:OAuth2RefreshTokenGrantConfig|http:BearerTokenConfig auth = let var authConfig = config.auth in
(authConfig is http:BearerTokenConfig ? authConfig : {...authConfig});
http:OAuth2RefreshTokenGrantConfig|http:BearerTokenConfig auth = let var authConfig = config.auth in
(authConfig is http:BearerTokenConfig ? authConfig : {...authConfig});
self.clientConfig = auth.cloneReadOnly();

http:ClientOAuth2Handler|http:ClientBearerTokenAuthHandler|error httpHandlerResult;
http:ClientOAuth2Handler|http:ClientBearerTokenAuthHandler httpHandlerResult;
if auth is http:OAuth2RefreshTokenGrantConfig {
httpHandlerResult = trap new http:ClientOAuth2Handler(auth);
httpHandlerResult = new http:ClientOAuth2Handler(auth);
} else {
httpHandlerResult = trap new http:ClientBearerTokenAuthHandler(auth);
httpHandlerResult = new http:ClientBearerTokenAuthHandler(auth);
}
self.clientHandler = httpHandlerResult;

if httpHandlerResult is http:ClientOAuth2Handler|http:ClientBearerTokenAuthHandler {
self.clientHandler = httpHandlerResult;
} else {
return error(utils:INVALID_CLIENT_CONFIG);
}

http:Client|error httpClientResult = trap new (config.baseUrl, httpClientConfig);
http:Client|http:ClientError httpClientResult = new (config.baseUrl, httpClientConfig);

if httpClientResult is http:Client {
self.salesforceClient = httpClientResult;
} else {
return error(utils:INVALID_CLIENT_CONFIG);
return error(utils:CLIENT_INIT_ERROR_MSG + httpClientResult.message(), httpClientResult);
}
}

Expand Down
3 changes: 1 addition & 2 deletions ballerina/modules/utils/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ const string QUESTION_MARK = "?";
# Constant field `EQUAL_SIGN`. Holds the value of "=".
const string EQUAL_SIGN = "=";

public const INVALID_CLIENT_CONFIG = "Invalid values provided for client configuration parameters.";
public const string CLIENT_INIT_ERROR_MSG = "Error occurred while initializing the client: ";
const ERR_EXTRACTING_ERROR_MSG = "Error occured while extracting errors from payload.";

0 comments on commit 28bf740

Please sign in to comment.