Skip to content

Commit

Permalink
server: CellBaseException extends WebApplicationException, #TASK-4976
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Sep 12, 2023
1 parent ad3ae74 commit 31e9d98
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
12 changes: 12 additions & 0 deletions cellbase-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>2.1.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>2.1.6</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package org.opencb.cellbase.core.exception;

public class CellBaseException extends Exception {
import javax.ws.rs.WebApplicationException;

public class CellBaseException extends WebApplicationException {

public CellBaseException(String msg) {
super(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
* limitations under the License.
*/

package org.opencb.cellbase.server.exception;
package org.opencb.cellbase.server.rest;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResponse;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.server.rest.GenericRestWSServer;
import org.opencb.commons.datastore.core.Event;
import org.opencb.commons.datastore.core.ObjectMap;
import org.opencb.commons.datastore.core.QueryOptions;
Expand All @@ -45,7 +43,7 @@
* Created by imedina on 02/03/16.
*/
@Provider
public class CellBaseExceptionMapper implements ExceptionMapper<CellBaseException> {
public class CellBaseExceptionMapper implements ExceptionMapper<Exception> {

@Context
private UriInfo uriInfo;
Expand All @@ -66,7 +64,7 @@ public class CellBaseExceptionMapper implements ExceptionMapper<CellBaseExceptio
}

@Override
public Response toResponse(CellBaseException e) {
public Response toResponse(Exception e) {
// First we print the exception in Server logs
logger.error("Catch error: " + e.getMessage(), e);

Expand All @@ -90,7 +88,8 @@ public Response toResponse(CellBaseException e) {
jsonObjectWriter.writeValueAsString(queryOptions),
ERROR);

return Response.ok(GenericRestWSServer.getJsonObjectWriter().writeValueAsString(queryResponse), MediaType.APPLICATION_JSON_TYPE)
return Response.ok(GenericRestWSServer.getJsonObjectWriter().writeValueAsString(queryResponse),
MediaType.APPLICATION_JSON_TYPE)
.status(Response.Status.INTERNAL_SERVER_ERROR)
.build();
} catch (JsonProcessingException e1) {
Expand Down

0 comments on commit 31e9d98

Please sign in to comment.