Skip to content

Commit

Permalink
User ApiUtils#serverError
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegismont authored and John Sanda committed May 26, 2015
1 parent 9c4891b commit f694064
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@

package org.hawkular.metrics.api.jaxrs.handler;

import static org.hawkular.metrics.api.jaxrs.util.ApiUtils.serverError;

import java.net.URI;
import java.util.function.Function;

import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.core.Response;

import org.hawkular.metrics.api.jaxrs.ApiError;

import com.google.common.base.Throwables;

import rx.Observer;

/**
Expand Down Expand Up @@ -75,9 +73,7 @@ public void onError(Throwable t) {
if (alreadyExistsException.isAssignableFrom(t.getClass())) {
response = alreadyExistsResponseBuilder.apply(alreadyExistsException.cast(t));
} else {
String message = "Failed to create tenant due to an unexpected error: "
+ Throwables.getRootCause(t).getMessage();
response = Response.serverError().entity(new ApiError(message)).build();
response = serverError(t, "Failed to create tenant due to an unexpected error");
}
asyncResponse.resume(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

import static org.hawkular.metrics.api.jaxrs.util.ApiUtils.collectionToResponse;
import static org.hawkular.metrics.api.jaxrs.util.ApiUtils.serverError;

import java.net.URI;

Expand All @@ -39,7 +40,6 @@
import org.hawkular.metrics.core.api.MetricsService;
import org.hawkular.metrics.core.api.Tenant;

import com.google.common.base.Throwables;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
Expand Down Expand Up @@ -97,11 +97,7 @@ public void createTenant(
public void findTenants(@Suspended AsyncResponse asyncResponse) {
metricsService.getTenants().toList().subscribe(
tenants -> asyncResponse.resume(collectionToResponse(tenants)),
error -> {
String msg = "Failed to perform operation due to an error: " + Throwables.getRootCause(error)
.getMessage();
asyncResponse.resume(Response.serverError().entity(new ApiError(msg)).build());
}
error -> asyncResponse.resume(serverError(error))
);
}
}

0 comments on commit f694064

Please sign in to comment.