Search in sources :

Example 51 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class OidcScopeManagementService method handleException.

/**
 * Handle error cases.
 *
 * @param e       Exception.
 * @param message Error message.
 * @return API error.
 */
private APIError handleException(IdentityOAuthAdminException e, String message) {
    ErrorResponse.Builder builder = new ErrorResponse.Builder().withCode(e.getErrorCode()).withMessage(message).withDescription(e.getMessage());
    ErrorResponse errorResponse = builder.build(LOG, e, message);
    Response.Status status;
    if (OidcScopeConstants.ErrorMessage.INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
        status = Response.Status.BAD_REQUEST;
    } else if (OidcScopeConstants.ErrorMessage.ERROR_CONFLICT_REQUEST.getCode().equals(e.getErrorCode())) {
        status = Response.Status.CONFLICT;
    } else if (OidcScopeConstants.ErrorMessage.SCOPE_NOT_FOUND.getCode().equals(e.getErrorCode())) {
        status = Response.Status.NOT_FOUND;
    } else {
        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) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 52 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class PermissionManagementService method handleException.

private APIError handleException(Exception e, String... data) {
    ErrorResponse errorResponse = getErrorBuilder(data).build(LOG, e, buildErrorDescription(data));
    Response.Status 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) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 53 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerUserStoreService method handleNotImplementedBehaviour.

/**
 * To return error responses for the input params for the get request which are not yet supported by the server.
 *
 * @param limit  items per page.
 * @param offset to specify the offset param.
 * @param filter to specify the filtering capabilities.
 * @param sort   to specify the sorting order.
 */
private void handleNotImplementedBehaviour(Integer limit, Integer offset, String filter, String sort) {
    UserStoreConstants.ErrorMessage errorEnum = null;
    if (limit != null) {
        errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
    } else if (offset != null) {
        errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_PAGINATION_NOT_IMPLEMENTED;
    } else if (filter != null) {
        errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_FILTERING_NOT_IMPLEMENTED;
    } else if (sort != null) {
        errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_SORTING_NOT_IMPLEMENTED;
    }
    if (errorEnum != null) {
        ErrorResponse errorResponse = getErrorBuilder(errorEnum).build(LOG, errorEnum.getDescription());
        Response.Status status = Response.Status.NOT_IMPLEMENTED;
        throw new APIError(status, errorResponse);
    }
}
Also used : UserStoreListResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse) UserStoreAttributeMappingResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) UserStoreResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse) ConnectionEstablishedResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) UserStoreConstants(org.wso2.carbon.identity.api.server.userstore.common.UserStoreConstants) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 54 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerUserStoreService method handleClaimManagementException.

/**
 * Handle ClaimManagementException, extract the error code and the error message from the corresponding
 * exception and set it to the API Error Response.
 *
 * @param exception     Exception thrown.
 * @param errorEnum     Corresponding error enum.
 * @return API Error object.
 */
private APIError handleClaimManagementException(ClaimMetadataException exception, UserStoreConstants.ErrorMessage errorEnum) {
    Response.Status status;
    ErrorResponse errorResponse;
    if (exception instanceof ClaimMetadataClientException) {
        errorResponse = getErrorBuilder(errorEnum).build(LOG, exception.getMessage());
        status = Response.Status.BAD_REQUEST;
        return handleClaimManagementClientException(exception, errorResponse, status);
    } else {
        // Internal Server error
        errorResponse = getErrorBuilder(errorEnum).build(LOG, exception, errorEnum.getDescription());
        status = Response.Status.INTERNAL_SERVER_ERROR;
        return new APIError(status, errorResponse);
    }
}
Also used : UserStoreListResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse) UserStoreAttributeMappingResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) UserStoreResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse) ConnectionEstablishedResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse) ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Aggregations

APIError (org.wso2.carbon.identity.api.server.common.error.APIError)52 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)47 Response (javax.ws.rs.core.Response)41 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)4 UserStoreAttributeMappingResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse)4 UserStoreListResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)4 UserStoreResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 ErrorMessage (org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage)3 FederatedAuthenticatorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse)3 IdentityProviderListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse)3 IdentityProviderResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse)3 IdentityProviderTemplateListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse)3 OutboundConnectorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse)3 ProvisioningResponse (org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningResponse)3 OwnerResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse)3 TenantsListResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)3 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)3 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)3