Skip to content

Commit

Permalink
Merge pull request #1712 from Avishka-Shamendra/master
Browse files Browse the repository at this point in the history
Improve Error Handling and Logging
  • Loading branch information
dushaniw authored Apr 17, 2024
2 parents 192b342 + 9c26fe5 commit 5b3fd9f
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
import org.apache.synapse.api.API;
import org.apache.synapse.api.Resource;
import org.apache.synapse.api.dispatch.DispatcherHelper;
Expand Down Expand Up @@ -883,15 +884,21 @@ private void addApi(OMElement apiElement, String fileName, boolean updateMode) t
persistApi(api);

} catch (Exception e) {
String errMsg = "Error trying to add the API to the ESB "
+ "configuration : " + api.getName();
api.destroy();
getSynapseConfiguration().removeAPI(api.getName());
try{
if (getAxisConfig().getService(api.getName()) != null) {
getAxisConfig().removeService(api.getName());
}
} catch (Exception ignore) {}
handleException(log, "Error trying to add the API to the ESB " +
"configuration : " + api.getName(), e);
try {
getSynapseConfiguration().removeAPI(api.getName());
if (getAxisConfig().getService(api.getName()) != null) {
getAxisConfig().removeService(api.getName());
}
} catch (SynapseException synapseException) {
// log previous exception and rethrow Synapse Exception
log.error(errMsg, e);
throw synapseException;
}
catch (Exception ignore) {}
handleException(log, errMsg, e);
}
}
} else {
Expand Down

0 comments on commit 5b3fd9f

Please sign in to comment.