use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementClientException in project carbon-identity-framework by wso2.
the class TemplateManagerImplTest method testErrorCodes.
@Test()
public void testErrorCodes() throws Exception {
DataSource dataSource = mock(DataSource.class);
mockDataSource(dataSource);
Template template = new Template(SUPER_TENANT_ID, null, "sample description", sampleScript);
String errorCode = TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_NAME_REQUIRED.getCode();
try (Connection connection = getConnection()) {
Connection spyConnection = spyConnection(connection);
when(dataSource.getConnection()).thenReturn(spyConnection);
TemplateManager templateManager = new TemplateManagerImpl();
try {
((TemplateManagerImpl) templateManager).addTemplateUsingTemplateMgtDAO(template);
} catch (TemplateManagementClientException e) {
String errorCode1 = e.getErrorCode();
Assert.assertEquals(errorCode, errorCode1);
}
}
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementClientException in project identity-api-server by wso2.
the class ServerIdpManagementService method handleTemplateMgtException.
/**
* Handle template management exceptions and return related API errors.
*
* @param e {@link TemplateManagementException}.
* @param errorEnum Error message with error code and description.
* @param data Additional information.
* @return API error.
*/
private APIError handleTemplateMgtException(TemplateManagementException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof TemplateManagementClientException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e.getMessage());
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof TemplateManagementServerException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
if (e.getErrorCode() != null) {
errorResponse = getErrorBuilder(e.getErrorCode(), e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
Aggregations