use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class NotificationSenderManagementService method handleTenantResourceManagementException.
private APIError handleTenantResourceManagementException(TenantResourceManagementException e, NotificationSenderManagementConstants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
Response.Status status;
if (e instanceof TenantResourceManagementClientException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(CONFIG_MGT_ERROR_CODE_DELIMITER) ? errorCode : NOTIFICATION_SENDER_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof TenantResourceManagementServerException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(CONFIG_MGT_ERROR_CODE_DELIMITER) ? errorCode : NOTIFICATION_SENDER_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class KeyStoreService method handleException.
private APIError handleException(KeyStoreManagementException e, String description) {
ErrorResponse.Builder builder = new ErrorResponse.Builder().withCode(e.getErrorCode()).withMessage(description).withDescription(e.getMessage());
Response.Status status;
ErrorResponse errorResponse;
if (e instanceof KeyStoreManagementServerException) {
errorResponse = builder.build(LOG, e, description);
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = builder.build(LOG, description);
status = Response.Status.BAD_REQUEST;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class KeyStoreService method handleException.
private APIError handleException(KeyStoreConstants.ErrorMessage errorMessage, String data, Exception e, Response.Status status) {
ErrorResponse.Builder builder = new ErrorResponse.Builder().withCode(errorMessage.getCode()).withMessage(generateErrorMessage(errorMessage.getMessage(), data)).withDescription(e.getMessage());
ErrorResponse errorResponse = builder.build(LOG, e, e.getMessage());
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class ServerScriptLibrariesService method handleScriptLibraryError.
/**
* Handle FunctionLibraryManagementExceptions, error description and status code to be sent
* in the response.
*
* @param e FunctionLibraryManagementException
* @param errorEnum Error Message information.
* @return APIError.
*/
private APIError handleScriptLibraryError(FunctionLibraryManagementException e, Constants.ErrorMessage errorEnum) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof FunctionLibraryManagementClientException) {
errorResponse = getErrorBuilder(errorEnum).build(log, e.getMessage());
createErrorResponse(e, errorResponse);
status = Response.Status.BAD_REQUEST;
} else if (e instanceof FunctionLibraryManagementServerException) {
errorResponse = getErrorBuilder(errorEnum).build(log, e, errorEnum.getDescription());
createErrorResponse(e, errorResponse);
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum).build(log, e, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class NotificationSendersApiServiceImpl method createSMSSender.
@Override
public Response createSMSSender(SMSSenderAdd smSSenderAdd) {
if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
return Response.status(Response.Status.METHOD_NOT_ALLOWED).build();
}
SMSSender smsSender = notificationSenderManagementService.addSMSSender(smSSenderAdd);
URI location = null;
try {
location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + NOTIFICATION_SENDER_CONTEXT_PATH + "/" + SMS_PUBLISHER_TYPE + "/" + URLEncoder.encode(smsSender.getName(), StandardCharsets.UTF_8.name()).replace(PLUS, URL_ENCODED_SPACE));
} catch (UnsupportedEncodingException e) {
ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build();
throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse);
}
return Response.created(location).entity(smsSender).build();
}
Aggregations