1package org.apache.archiva.redback.rest.services.interceptors;
2/*3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 */2021import org.apache.archiva.redback.rest.api.model.RedbackRestError;
22import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
23import org.springframework.stereotype.Service;
2425import javax.ws.rs.core.Response;
26import javax.ws.rs.ext.ExceptionMapper;
27import javax.ws.rs.ext.Provider;
2829/**30 * @author Olivier Lamy31 * @since 1.4-M232 */33 @Provider
34 @Service( "redbackServiceExceptionMapper" )
35publicclassRedbackServiceExceptionMapper36implements ExceptionMapper<RedbackServiceException>
37 {
38public Response toResponse( final RedbackServiceException e )
39 {
40RedbackRestError restError = newRedbackRestError( e );
4142 Response.ResponseBuilder responseBuilder = Response.status( e.getHttpErrorCode() ).entity( restError );
43if ( e.getMessage() != null )
44 {
45 responseBuilder = responseBuilder.status( new Response.StatusType()
46 {
47publicint getStatusCode()
48 {
49return e.getHttpErrorCode();
50 }
5152public Response.Status.Family getFamily()
53 {
54return Response.Status.Family.SERVER_ERROR;
55 }
5657public String getReasonPhrase()
58 {
59return e.getMessage();
60 }
61 } );
62 }
63return responseBuilder.build();
64 }
65 }