Search in sources :

Example 46 with APIError

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);
}
Also used : Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantResourceManagementServerException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementServerException) TenantResourceManagementClientException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 47 with APIError

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);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) CertificateResponse(org.wso2.carbon.identity.api.server.keystore.management.v1.model.CertificateResponse) Response(javax.ws.rs.core.Response) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) KeyStoreManagementServerException(org.wso2.carbon.security.keystore.KeyStoreManagementServerException) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 48 with APIError

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);
}
Also used : APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 49 with APIError

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);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) ScriptLibraryResponse(org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryResponse) ScriptLibraryListResponse(org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryListResponse) Response(javax.ws.rs.core.Response) FunctionLibraryManagementClientException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) FunctionLibraryManagementServerException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementServerException)

Example 50 with APIError

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();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) SMSSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSender) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) URI(java.net.URI) 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