mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-27 00:40:51 +01:00
52 lines
1.7 KiB
Java
52 lines
1.7 KiB
Java
/*
|
|
* Copyright (c) 2020 - present Cloudogu GmbH
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*
|
|
* 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/.
|
|
*/
|
|
|
|
package sonia.scm.api;
|
|
|
|
import jakarta.ws.rs.NotFoundException;
|
|
import jakarta.ws.rs.core.Response;
|
|
import jakarta.ws.rs.ext.ExceptionMapper;
|
|
import jakarta.ws.rs.ext.Provider;
|
|
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();
|
|
}
|
|
}
|