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;
}
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();
}
Aggregations