Migrate NotSupportedFeatureException

This commit is contained in:
René Pfeuffer
2018-11-02 16:21:23 +01:00
parent a1f16713cc
commit 359a857ca3
4 changed files with 34 additions and 5 deletions

View File

@@ -33,17 +33,30 @@
package sonia.scm;
import java.util.Collections;
/**
*
* @author Sebastian Sdorra
* @version 1.6
*/
public class NotSupportedFeatureException extends Exception {
public class NotSupportedFeatureException extends ExceptionWithContext {
private static final long serialVersionUID = 256498734456613496L;
public NotSupportedFeatureException(String message)
private static final String CODE = "9SR8G0kmU1";
public NotSupportedFeatureException(String feature)
{
super(message);
super(Collections.emptyList(),createMessage(feature));
}
@Override
public String getCode() {
return CODE;
}
private static String createMessage(String feature) {
return "feature " + feature + " is not supported by this repository";
}
}

View File

@@ -170,8 +170,7 @@ public abstract class AbstractRepositoryHandler<C extends RepositoryConfig>
@Override
public ImportHandler getImportHandler() throws NotSupportedFeatureException
{
throw new NotSupportedFeatureException(
"import handler is not supported by this repository handler");
throw new NotSupportedFeatureException("import");
}
/**

View File

@@ -0,0 +1,15 @@
package sonia.scm.api.v2;
import sonia.scm.NotSupportedFeatureException;
import sonia.scm.api.rest.ContextualExceptionMapper;
import sonia.scm.api.v2.resources.ExceptionWithContextToErrorDtoMapper;
import javax.inject.Inject;
import javax.ws.rs.core.Response;
public class NotSupportedFeatureExceptionMapper extends ContextualExceptionMapper<NotSupportedFeatureException> {
@Inject
public NotSupportedFeatureExceptionMapper(ExceptionWithContextToErrorDtoMapper mapper) {
super(NotSupportedFeatureException.class, Response.Status.BAD_REQUEST, mapper);
}
}

View File

@@ -7,6 +7,7 @@ import sonia.scm.api.rest.AuthorizationExceptionMapper;
import sonia.scm.api.rest.ConcurrentModificationExceptionMapper;
import sonia.scm.api.rest.IllegalArgumentExceptionMapper;
import sonia.scm.api.v2.NotFoundExceptionMapper;
import sonia.scm.api.v2.NotSupportedFeatureExceptionMapper;
public class DispatcherMock {
public static Dispatcher createDispatcher(Object resource) {
@@ -21,6 +22,7 @@ public class DispatcherMock {
dispatcher.getProviderFactory().register(new ChangePasswordNotAllowedExceptionMapper(mapper));
dispatcher.getProviderFactory().register(new InvalidPasswordExceptionMapper(mapper));
dispatcher.getProviderFactory().registerProvider(IllegalArgumentExceptionMapper.class);
dispatcher.getProviderFactory().register(new NotSupportedFeatureExceptionMapper(mapper));
return dispatcher;
}
}