Search in sources :

Example 1 with CustomerFacingException

use of org.platformlayer.CustomerFacingException in project platformlayer by platformlayer.

the class RegisterResource method register.

private RegistrationResponse register(RegistrationRequest request) {
    RegistrationResponse response = new RegistrationResponse();
    String username = request.username;
    String password = request.password;
    UserEntity userEntity;
    try {
        OpsUser user = registrationService.registerUser(username, password);
        userEntity = (UserEntity) user;
    } catch (CustomerFacingException e) {
        response.errorMessage = e.getMessage();
        return response;
    }
    if (userEntity == null) {
        log.warn("Authentication request failed immediately after registration.  Username=" + username);
        throw new IllegalStateException();
    }
    response.access = tokenHelpers.buildAccess(userEntity);
    return response;
}
Also used : CustomerFacingException(org.platformlayer.CustomerFacingException) OpsUser(org.platformlayer.auth.OpsUser) RegistrationResponse(org.platformlayer.auth.model.RegistrationResponse) UserEntity(org.platformlayer.auth.UserEntity)

Example 2 with CustomerFacingException

use of org.platformlayer.CustomerFacingException in project platformlayer by platformlayer.

the class OpsExceptionMapper method toResponse.

@Override
public Response toResponse(OpsException e) {
    log.warn("Returning error to client", e);
    ErrorResponse error = new ErrorResponse();
    error.message = e.getMessage();
    if (e instanceof CustomerFacingException) {
        CustomerFacingException cfe = (CustomerFacingException) e;
        error.code = cfe.getCode();
        for (CustomerFacingException.Info info : cfe.getInfo()) {
            ErrorDetail errorInfo = new ErrorDetail();
            errorInfo.code = info.getCode();
            errorInfo.field = info.getField();
            errorInfo.message = info.getMessage();
            error.details.add(errorInfo);
        }
    }
    if (error.code == null) {
        error.code = e.getClass().getSimpleName();
    }
    ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
    response.entity(error);
    return response.build();
// VariantListBuilder variantListBuilder = VariantListBuilder.newInstance();
// variantListBuilder.mediaTypes(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE);
// List<Variant> variants = variantListBuilder.build();
// 
// Variant variant = httpContext.getRequest().selectVariant(variants);
// 
// ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
// 
// if (variant.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)) {
// response.entity(error);
// 
// .entity(exception.getMessage()).type("text/plain").build();
// }
// else {
// .entity(exception.getMessage()).type("text/plain").build();
// }
// 
// return response.build();
}
Also used : ErrorDetail(org.platformlayer.core.model.ErrorDetail) CustomerFacingException(org.platformlayer.CustomerFacingException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ErrorResponse(org.platformlayer.core.model.ErrorResponse)

Aggregations

CustomerFacingException (org.platformlayer.CustomerFacingException)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 OpsUser (org.platformlayer.auth.OpsUser)1 UserEntity (org.platformlayer.auth.UserEntity)1 RegistrationResponse (org.platformlayer.auth.model.RegistrationResponse)1 ErrorDetail (org.platformlayer.core.model.ErrorDetail)1 ErrorResponse (org.platformlayer.core.model.ErrorResponse)1