Fix response code

This commit is contained in:
Leonardo Loch Zanivan 2015-05-13 15:39:32 -03:00
parent dbf9525860
commit abcd830af1
2 changed files with 9 additions and 11 deletions

View file

@ -11,9 +11,7 @@ import javax.ws.rs.core.Response;
public class ErrorResponse { public class ErrorResponse {
public static Response exists(String message) { public static Response exists(String message) {
ErrorRepresentation error = new ErrorRepresentation(); return ErrorResponse.error(message, Response.Status.CONFLICT);
error.setErrorMessage(message);
return Response.status(Response.Status.CONFLICT).entity(error).type(MediaType.APPLICATION_JSON).build();
} }
public static Response error(String message, Response.Status status) { public static Response error(String message, Response.Status status) {

View file

@ -202,11 +202,11 @@ public class RealmAdminResource {
adminEvent.operation(OperationType.UPDATE).resourcePath(uriInfo.getPath()).representation(rep).success(); adminEvent.operation(OperationType.UPDATE).resourcePath(uriInfo.getPath()).representation(rep).success();
return Response.noContent().build(); return Response.noContent().build();
} catch (PatternSyntaxException e) { } catch (PatternSyntaxException e) {
return ErrorResponse.exists("Specified regex pattern(s) is invalid."); return ErrorResponse.error("Specified regex pattern(s) is invalid.", Response.Status.BAD_REQUEST);
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {
return ErrorResponse.exists("Realm " + rep.getRealm() + " already exists."); return ErrorResponse.exists("Realm " + rep.getRealm() + " already exists.");
} catch (Exception e) { } catch (Exception e) {
return ErrorResponse.exists("Failed to update " + rep.getRealm() + " Realm."); return ErrorResponse.error("Failed to update " + rep.getRealm() + " Realm.", Response.Status.INTERNAL_SERVER_ERROR);
} }
} }