use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.
the class BrandingPreferenceApiServiceImpl method addBrandingPreference.
// TODO: Improve API to manage application level & language level theming resources in addition to the tenant level.
@Override
public Response addBrandingPreference(BrandingPreferenceModel brandingPreferenceModel) {
if (StringUtils.isBlank(brandingPreferenceModel.getType().toString())) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (!ORGANIZATION_TYPE.equals(brandingPreferenceModel.getType().toString())) {
return Response.status(Response.Status.NOT_IMPLEMENTED).entity("Not Implemented.").build();
}
if ((!DEFAULT_LOCALE.equals(brandingPreferenceModel.getLocale())) && StringUtils.isNotBlank(brandingPreferenceModel.getLocale())) {
return Response.status(Response.Status.NOT_IMPLEMENTED).entity("Not Implemented.").build();
}
BrandingPreferenceModel createdBrandingPreferenceModel = brandingPreferenceManagementService.addBrandingPreference(brandingPreferenceModel);
URI location = null;
try {
location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + BRANDING_PREFERENCE_CONTEXT_PATH + QUERY_PARAM_INDICATOR + URLEncoder.encode(String.format(GET_PREFERENCE_COMPONENT_WITH_QUERY_PARAM, ORGANIZATION_TYPE, getTenantDomainFromContext(), DEFAULT_LOCALE), StandardCharsets.UTF_8.name()));
} 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(createdBrandingPreferenceModel).build();
}
use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.
the class ServerAuthenticatorManagementService method handleApplicationMgtException.
/**
* Handle IdentityApplicationManagementException, extract error code, error description and status code to be sent
* in the response.
*
* @param e IdentityApplicationManagementException
* @param errorEnum Error information.
* @return APIError.
*/
private APIError handleApplicationMgtException(IdentityApplicationManagementException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof IdentityApplicationManagementClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof IdentityApplicationManagementServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).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.ErrorResponse in project identity-api-server by wso2.
the class ServerAuthenticatorManagementService method handleNotImplementedCapabilities.
private void handleNotImplementedCapabilities(Integer limit, Integer offset) {
Constants.ErrorMessage errorEnum = null;
if (limit != null || offset != null) {
errorEnum = Constants.ErrorMessage.ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
}
if (errorEnum != null) {
ErrorResponse errorResponse = getErrorBuilder(errorEnum, null).build(log, errorEnum.getDescription());
Response.Status status = Response.Status.NOT_IMPLEMENTED;
throw new APIError(status, errorResponse);
}
}
use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.
the class ServerClaimManagementService method handleException.
private APIError handleException(Exception e, Constant.ErrorMessage errorEnum, String... data) {
ErrorResponse errorResponse = getErrorBuilder(errorEnum, data).build(LOG, e, buildErrorDescription(errorEnum, data));
Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.ErrorResponse in project identity-api-server by wso2.
the class ServerIdentityGovernanceService method handleNotFoundError.
private APIError handleNotFoundError(String resourceId, GovernanceConstants.ErrorMessage errorMessage) {
Response.Status status = Response.Status.NOT_FOUND;
ErrorResponse errorResponse = getErrorBuilder(errorMessage, resourceId).build(LOG, errorMessage.getDescription());
return new APIError(status, errorResponse);
}
Aggregations