Search in sources :

Example 1 with BrandingPreferenceMgtServerException

use of org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtServerException in project identity-api-server by wso2.

the class BrandingPreferenceManagementService method handleBrandingPreferenceMgtException.

/**
 * Handle branding preference management exceptions and return an API error.
 *
 * @param exception Branding preference management exception
 * @param errorEnum Branding preference management error enum.
 * @param data      Relevant data.
 * @return Processed API Error.
 */
private APIError handleBrandingPreferenceMgtException(BrandingPreferenceMgtException exception, BrandingPreferenceManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (exception instanceof BrandingPreferenceMgtClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, exception.getMessage());
        if (exception.getErrorCode() != null) {
            String errorCode = exception.getErrorCode();
            errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(exception.getMessage());
        if (BRANDING_PREFERENCE_ALREADY_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
            status = Response.Status.CONFLICT;
        } else if (BRANDING_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
            status = Response.Status.NOT_FOUND;
        } else {
            status = Response.Status.BAD_REQUEST;
        }
    } else if (exception instanceof BrandingPreferenceMgtServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, errorEnum.getDescription());
        if (exception.getErrorCode() != null) {
            String errorCode = exception.getErrorCode();
            errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(exception.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, errorEnum.getDescription());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) BrandingPreferenceMgtServerException(org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) BrandingPreferenceMgtClientException(org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtClientException)

Aggregations

Response (javax.ws.rs.core.Response)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1 BrandingPreferenceMgtClientException (org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtClientException)1 BrandingPreferenceMgtServerException (org.wso2.carbon.identity.branding.preference.management.core.exception.BrandingPreferenceMgtServerException)1