Skip to content

Commit 03008c9

Browse files
Added internal server error exception
1 parent 8ff00d2 commit 03008c9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

couchdb/src/main/java/me/retrodaredevil/couchdbjava/CouchDbStatusCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ private CouchDbStatusCode() {
1515
public static final int NOT_FOUND = 404;
1616
public static final int UPDATE_CONFLICT = 409;
1717
public static final int PRECONDITION_FAILED = 412;
18+
public static final int INTERNAL_SERVER_ERROR = 500;
1819
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.retrodaredevil.couchdbjava.exception;
2+
3+
import me.retrodaredevil.couchdbjava.CouchDbStatusCode;
4+
import me.retrodaredevil.couchdbjava.response.ErrorResponse;
5+
import org.jetbrains.annotations.Nullable;
6+
7+
public class CouchDbInternalServerErrorException extends CouchDbCodeException {
8+
public CouchDbInternalServerErrorException(@Nullable ErrorResponse errorResponse) {
9+
super(CouchDbStatusCode.INTERNAL_SERVER_ERROR, errorResponse);
10+
}
11+
12+
public CouchDbInternalServerErrorException(String message, @Nullable ErrorResponse errorResponse) {
13+
super(message, CouchDbStatusCode.INTERNAL_SERVER_ERROR, errorResponse);
14+
}
15+
16+
public CouchDbInternalServerErrorException(String message, Throwable cause, @Nullable ErrorResponse errorResponse) {
17+
super(message, cause, CouchDbStatusCode.INTERNAL_SERVER_ERROR, errorResponse);
18+
}
19+
20+
public CouchDbInternalServerErrorException(Throwable cause, @Nullable ErrorResponse errorResponse) {
21+
super(cause, CouchDbStatusCode.INTERNAL_SERVER_ERROR, errorResponse);
22+
}
23+
24+
public CouchDbInternalServerErrorException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, @Nullable ErrorResponse errorResponse) {
25+
super(message, cause, enableSuppression, writableStackTrace, CouchDbStatusCode.INTERNAL_SERVER_ERROR, errorResponse);
26+
}
27+
}

couchdb/src/main/java/me/retrodaredevil/couchdbjava/okhttp/util/OkHttpUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private static CouchDbException createException(ErrorResponse error, int code) {
7373
if (error != null) {
7474
additionalString = " error: " + error.getError() + " reason: " + error.getReason();
7575
}
76+
// https://docs.couchdb.org/en/stable/api/basics.html#http-status-codes
7677
switch(code) {
7778
case CouchDbStatusCode.NOT_MODIFIED:
7879
return new CouchDbNotModifiedException("Not modified!" + additionalString, error);
@@ -84,6 +85,8 @@ private static CouchDbException createException(ErrorResponse error, int code) {
8485
return new CouchDbUpdateConflictException("Update conflict!" + additionalString, error);
8586
case CouchDbStatusCode.BAD_REQUEST:
8687
return new CouchDbBadRequestException("Bad request!" + additionalString, error);
88+
case CouchDbStatusCode.INTERNAL_SERVER_ERROR:
89+
return new CouchDbInternalServerErrorException("Internal server error!" + additionalString, error);
8790
}
8891
return new CouchDbCodeException("Unknown status code! code: " + code + additionalString, code, error);
8992
}

0 commit comments

Comments
 (0)