Skip to content

Commit 7f492fc

Browse files
authored
Merge pull request #28 from G8XSU/auth_exception
Add AuthException
2 parents 187c6bc + 7e0057f commit 7f492fc

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

app/src/main/java/org/vss/api/AbstractVssApi.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.vss.ErrorCode;
88
import org.vss.ErrorResponse;
99
import org.vss.KVStore;
10+
import org.vss.exception.AuthException;
1011
import org.vss.exception.ConflictException;
1112
import org.vss.exception.NoSuchKeyException;
1213

@@ -39,6 +40,9 @@ Response toErrorResponse(Exception e) {
3940
} else if (e instanceof NoSuchKeyException) {
4041
errorCode = ErrorCode.NO_SUCH_KEY_EXCEPTION;
4142
statusCode = 404;
43+
} else if (e instanceof AuthException) {
44+
errorCode = ErrorCode.AUTH_EXCEPTION;
45+
statusCode = 401;
4246
} else {
4347
errorCode = ErrorCode.INTERNAL_SERVER_EXCEPTION;
4448
statusCode = 500;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.vss.exception;
2+
3+
public class AuthException extends RuntimeException {
4+
public AuthException(String message) {
5+
super(message);
6+
}
7+
}

app/src/main/proto/vss.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ enum ErrorCode {
268268

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

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

283283
// Used when the specified `key` in a `GetObjectRequest` does not exist.
284284
NO_SUCH_KEY_EXCEPTION = 4;
285+
286+
// Used when authentication fails or in case of an unauthorized request.
287+
AUTH_EXCEPTION = 5;
285288
}
286289

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

0 commit comments

Comments
 (0)