Skip to content

Commit

Permalink
Merge pull request #6 from trocco-io/detail_error_log
Browse files Browse the repository at this point in the history
salesforce例外時のログを出力する
  • Loading branch information
hid3h authored Feb 26, 2022
2 parents 2604baf + 5323bdb commit 0c381ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ configurations {
provided
}

version = "0.1.7"
version = "0.1.8"

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
52 changes: 17 additions & 35 deletions src/main/java/org/embulk/output/sf_bulk_api/ForceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,45 +64,27 @@ private ConnectorConfig createConnectorConfig(final PluginTask pluginTask)
return config;
}

private void insert(final List<SObject> sObjects)
{
try {
final SaveResult[] saveResultArray = partnerConnection.create(sObjects.toArray(new SObject[sObjects.size()]));
loggingSaveErrorMessage(saveResultArray);
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
private void insert(final List<SObject> sObjects) throws ConnectionException {
final SaveResult[] saveResultArray = partnerConnection.create(sObjects.toArray(new SObject[sObjects.size()]));
loggingSaveErrorMessage(saveResultArray);
}

private void upsert(final String key, final List<SObject> sObjects)
{
try {
final UpsertResult[] upsertResultArray = partnerConnection.upsert(key, sObjects.toArray(new SObject[sObjects.size()]));
final List<UpsertResult> upsertResults = Arrays.asList(upsertResultArray);
upsertResults.forEach(result -> {
if (!result.isSuccess()) {
final List<String> errors = Arrays.asList(result.getErrors())
.stream().map(e -> e.getStatusCode() + ":" + e.getMessage())
.collect(Collectors.toList());
logger.warn(String.join(",", errors));
}
});
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
private void upsert(final String key, final List<SObject> sObjects) throws ConnectionException {
final UpsertResult[] upsertResultArray = partnerConnection.upsert(key, sObjects.toArray(new SObject[sObjects.size()]));
final List<UpsertResult> upsertResults = Arrays.asList(upsertResultArray);
upsertResults.forEach(result -> {
if (!result.isSuccess()) {
final List<String> errors = Arrays.asList(result.getErrors())
.stream().map(e -> e.getStatusCode() + ":" + e.getMessage())
.collect(Collectors.toList());
logger.warn(String.join(",", errors));
}
});
}

private void update(final List<SObject> sObjects)
{
try {
final SaveResult[] saveResultArray = partnerConnection.update(sObjects.toArray(new SObject[sObjects.size()]));
loggingSaveErrorMessage(saveResultArray);
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
private void update(final List<SObject> sObjects) throws ConnectionException {
final SaveResult[] saveResultArray = partnerConnection.update(sObjects.toArray(new SObject[sObjects.size()]));
loggingSaveErrorMessage(saveResultArray);
}

private void loggingSaveErrorMessage(final SaveResult[] saveResultArray)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import com.sforce.soap.partner.fault.ApiFault;
import com.sforce.soap.partner.sobject.SObject;
import com.sforce.ws.ConnectionException;

Expand Down Expand Up @@ -54,7 +55,10 @@ public void add(Page page)
forceClient.action(records);
}
}
catch (ConnectionException e) {
catch (ApiFault e) {
logger.error(e.getExceptionCode().toString() + ":" + e.getExceptionMessage(), e);
}
catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
Expand Down

0 comments on commit 0c381ff

Please sign in to comment.