Skip to content

Commit

Permalink
Add AuthException
Browse files Browse the repository at this point in the history
It will be used when an unauthorized request is made
or we fail to authenticate from headers.
  • Loading branch information
G8XSU committed Apr 30, 2024
1 parent 187c6bc commit 83af81b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/src/main/java/org/vss/api/AbstractVssApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.vss.ErrorCode;
import org.vss.ErrorResponse;
import org.vss.KVStore;
import org.vss.exception.AuthException;
import org.vss.exception.ConflictException;
import org.vss.exception.NoSuchKeyException;

Expand Down Expand Up @@ -39,6 +40,9 @@ Response toErrorResponse(Exception e) {
} else if (e instanceof NoSuchKeyException) {
errorCode = ErrorCode.NO_SUCH_KEY_EXCEPTION;
statusCode = 404;
} else if (e instanceof AuthException) {
errorCode = ErrorCode.AUTH_EXCEPTION;
statusCode = 401;
} else {
errorCode = ErrorCode.INTERNAL_SERVER_EXCEPTION;
statusCode = 500;
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/org/vss/exception/AuthException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.vss.exception;

public class AuthException extends RuntimeException {
public AuthException(String message) {
super(message);
}
}
5 changes: 4 additions & 1 deletion app/src/main/proto/vss.proto
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ enum ErrorCode {

// Used when the request contains mismatched version (either key or global)
// in `PutObjectRequest`. For more info refer `PutObjectRequest`.
CONFLICT_EXCEPTION= 1;
CONFLICT_EXCEPTION = 1;

// Used in the following cases:
// - The request was missing a required argument.
Expand All @@ -282,6 +282,9 @@ enum ErrorCode {

// Used when the specified `key` in a `GetObjectRequest` does not exist.
NO_SUCH_KEY_EXCEPTION = 4;

// Used when authentication fails or in case of an unauthorized request.
AUTH_EXCEPTION = 5;
}

// Represents a key-value pair to be stored or retrieved.
Expand Down

0 comments on commit 83af81b

Please sign in to comment.