2020-03-23 15:35:58 +01:00
|
|
|
/*
|
2024-09-24 09:42:07 +02:00
|
|
|
* Copyright (c) 2020 - present Cloudogu GmbH
|
2020-03-23 15:35:58 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
|
* Software Foundation, version 3.
|
2020-03-23 15:35:58 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
|
* details.
|
2020-03-23 15:35:58 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
2020-03-23 15:35:58 +01:00
|
|
|
*/
|
2024-09-24 09:42:07 +02:00
|
|
|
|
2018-12-14 10:42:19 +01:00
|
|
|
package sonia.scm.api;
|
|
|
|
|
|
2023-11-29 18:14:03 +01:00
|
|
|
import jakarta.ws.rs.NotFoundException;
|
|
|
|
|
import jakarta.ws.rs.core.Response;
|
|
|
|
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
|
|
|
|
import jakarta.ws.rs.ext.Provider;
|
2018-12-14 10:42:19 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.slf4j.MDC;
|
|
|
|
|
import sonia.scm.api.v2.resources.ErrorDto;
|
|
|
|
|
import sonia.scm.web.VndMediaType;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
@Provider
|
|
|
|
|
public class JaxNotFoundExceptionMapper implements ExceptionMapper<NotFoundException> {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(JaxNotFoundExceptionMapper.class);
|
|
|
|
|
|
|
|
|
|
private static final String ERROR_CODE = "92RCCCMHO1";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Response toResponse(NotFoundException exception) {
|
|
|
|
|
logger.debug(exception.getMessage());
|
|
|
|
|
ErrorDto errorDto = new ErrorDto();
|
|
|
|
|
errorDto.setMessage("path not found");
|
|
|
|
|
errorDto.setContext(Collections.emptyList());
|
|
|
|
|
errorDto.setErrorCode(ERROR_CODE);
|
|
|
|
|
errorDto.setTransactionId(MDC.get("transaction_id"));
|
|
|
|
|
return Response.status(Response.Status.NOT_FOUND)
|
|
|
|
|
.entity(errorDto)
|
|
|
|
|
.type(VndMediaType.ERROR_TYPE)
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|