blob: 27b72808efb35aa73854cba79cc47b57ee30857b [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
package org.eclipse.mdm.apicopy.entity;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.Provider;
import org.eclipse.mdm.apicopy.control.ApiCopyException;
import org.eclipse.mdm.apicopy.entity.CopyStatusResponse.State;
import com.google.common.base.Throwables;
/**
* Maps {@link ApiCopyException} to a HTTP BAD Request and provides
* {@link CopyStatusResponse} in the payload.
*/
@Provider
public class ApiCopyExceptionMapper implements javax.ws.rs.ext.ExceptionMapper<ApiCopyException> {
/**
* {@inheritDoc}
*/
@Override
public Response toResponse(ApiCopyException e) {
CopyStatusResponse status = new CopyStatusResponse();
status.setState(State.FAILED);
status.setMessage(e.getMessage());
status.setStacktrace(Throwables.getStackTraceAsString(e));
return Response.status(Status.BAD_REQUEST).entity(status).build();
}
}