Skip to content
Snippets Groups Projects
Commit 95c1d745 authored by Lars Johansson's avatar Lars Johansson
Browse files

Remove unused exceptions

parent b647ee8c
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.openepics.names.util; package org.openepics.names.util;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
/** /**
* Utility class to assist in handling of exceptions. * Utility class to assist in handling of exceptions.
...@@ -49,117 +48,6 @@ public class ExceptionUtil { ...@@ -49,117 +48,6 @@ public class ExceptionUtil {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
/**
* Convert service http status exception to response status exception.
*
* @param e service http status exception
* @return response status exception
*/
public static ResponseStatusException convertException(ServiceHttpStatusException e) {
switch (e.getHttpStatus()) {
case BAD_REQUEST:
throw ExceptionUtil.createResponseStatusExceptionBadRequest();
case UNAUTHORIZED:
throw ExceptionUtil.createResponseStatusExceptionUnauthorized();
case FORBIDDEN:
throw ExceptionUtil.createResponseStatusExceptionForbidden();
case NOT_FOUND:
throw ExceptionUtil.createResponseStatusExceptionNotFound();
case CONFLICT:
throw ExceptionUtil.createResponseStatusExceptionConflict();
case INTERNAL_SERVER_ERROR:
throw ExceptionUtil.createResponseStatusExceptionInternalServerError();
case NOT_IMPLEMENTED:
throw ExceptionUtil.createResponseStatusExceptionNotImplemented();
default:
throw ExceptionUtil.createResponseStatusExceptionInternalServerError();
}
}
/**
* Create response status exception.
* Intended for communication from server to client.
*
* @param status http status
* @param reason reason
* @param cause cause
* @return response status exception
*/
protected static ResponseStatusException createResponseStatusException(HttpStatus status, String reason, Throwable cause) {
return new ResponseStatusException(status, reason, cause);
}
/**
* Create response status exception for {@link HttpStatus#BAD_REQUEST}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected static ResponseStatusException createResponseStatusExceptionBadRequest() {
return createResponseStatusException(HttpStatus.BAD_REQUEST, OPERATION_COULD_NOT_BE_PERFORMED, null);
}
/**
* Create response status exception for {@link HttpStatus#UNAUTHORIZED}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected static ResponseStatusException createResponseStatusExceptionUnauthorized() {
return createResponseStatusException(HttpStatus.UNAUTHORIZED, OPERATION_COULD_NOT_BE_PERFORMED, null);
}
/**
* Create response status exception for {@link HttpStatus#FORBIDDEN}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected static ResponseStatusException createResponseStatusExceptionForbidden() {
return createResponseStatusException(HttpStatus.FORBIDDEN, OPERATION_COULD_NOT_BE_PERFORMED, null);
}
/**
* Create response status exception for {@link HttpStatus#NOT_FOUND}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected static ResponseStatusException createResponseStatusExceptionNotFound() {
return createResponseStatusException(HttpStatus.NOT_FOUND, OPERATION_COULD_NOT_BE_PERFORMED, null);
}
/**
* Create response status exception for {@link HttpStatus#CONFLICT}.
* Intended for communication from server to client.
*
* @return response status exception
*/
protected static ResponseStatusException createResponseStatusExceptionConflict() {
return createResponseStatusException(HttpStatus.CONFLICT, OPERATION_COULD_NOT_BE_PERFORMED, null);
}
/**
* Create response status exception for {@link HttpStatus#INTERNAL_SERVER_ERROR}.
* Intended for communication from server to client.
*
* @return response status exception
*/
public static ResponseStatusException createResponseStatusExceptionInternalServerError() {
return createResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, OPERATION_COULD_NOT_BE_PERFORMED, null);
}
/**
* Create response status exception for {@link HttpStatus#NOT_IMPLEMENTED}.
* Intended for communication from server to client.
*
* @return response status exception
*/
public static ResponseStatusException createResponseStatusExceptionNotImplemented() {
return createResponseStatusException(HttpStatus.NOT_IMPLEMENTED, OPERATION_COULD_NOT_BE_PERFORMED, null);
}
/** /**
* Create service http status exception. * Create service http status exception.
* Intended for communication inside server. * Intended for communication inside server.
......
...@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; ...@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
/** /**
* Unit tests for ExceptionUtil class. * Unit tests for ExceptionUtil class.
...@@ -34,52 +33,6 @@ import org.springframework.web.server.ResponseStatusException; ...@@ -34,52 +33,6 @@ import org.springframework.web.server.ResponseStatusException;
*/ */
public class ExceptionUtilTest { public class ExceptionUtilTest {
/**
* Test of create response status exception.
*/
@Test
public void createResponseStatusException() {
ResponseStatusException exception = ExceptionUtil.createResponseStatusException(HttpStatus.I_AM_A_TEAPOT, null, null);
assertEquals(HttpStatus.I_AM_A_TEAPOT, exception.getStatus());
assertNull (exception.getReason());
assertNull (exception.getCause());
exception = ExceptionUtil.createResponseStatusExceptionBadRequest();
assertEquals(HttpStatus.BAD_REQUEST, exception.getStatus());
assertEquals(ExceptionUtil.OPERATION_COULD_NOT_BE_PERFORMED, exception.getReason());
assertEquals(null, exception.getCause());
exception = ExceptionUtil.createResponseStatusExceptionUnauthorized();
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatus());
assertEquals(ExceptionUtil.OPERATION_COULD_NOT_BE_PERFORMED, exception.getReason());
assertEquals(null, exception.getCause());
exception = ExceptionUtil.createResponseStatusExceptionForbidden();
assertEquals(HttpStatus.FORBIDDEN, exception.getStatus());
assertEquals(ExceptionUtil.OPERATION_COULD_NOT_BE_PERFORMED, exception.getReason());
assertEquals(null, exception.getCause());
exception = ExceptionUtil.createResponseStatusExceptionNotFound();
assertEquals(HttpStatus.NOT_FOUND, exception.getStatus());
assertEquals(ExceptionUtil.OPERATION_COULD_NOT_BE_PERFORMED, exception.getReason());
assertEquals(null, exception.getCause());
exception = ExceptionUtil.createResponseStatusExceptionConflict();
assertEquals(HttpStatus.CONFLICT, exception.getStatus());
assertEquals(ExceptionUtil.OPERATION_COULD_NOT_BE_PERFORMED, exception.getReason());
assertEquals(null, exception.getCause());
exception = ExceptionUtil.createResponseStatusExceptionInternalServerError();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exception.getStatus());
assertEquals(ExceptionUtil.OPERATION_COULD_NOT_BE_PERFORMED, exception.getReason());
assertEquals(null, exception.getCause());
exception = ExceptionUtil.createResponseStatusExceptionNotImplemented();
assertEquals(HttpStatus.NOT_IMPLEMENTED, exception.getStatus());
assertEquals(ExceptionUtil.OPERATION_COULD_NOT_BE_PERFORMED, exception.getReason());
assertEquals(null, exception.getCause());
}
/** /**
* Test of create service http status exception. * Test of create service http status exception.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment