Skip to content

Commit 8dbb71e

Browse files
committed
Error code is a string.
1 parent a2ab411 commit 8dbb71e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/main/kotlin/com/github/mduesterhoeft/router/ApiException.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import java.lang.RuntimeException
55
class ApiException(
66
val statusCode: Int = 400,
77
message: String,
8-
val errorCode: Int,
8+
val code: String,
99
val details: Map<String, Any> = emptyMap()
1010
) : RuntimeException(message) {
1111

1212
override fun toString(): String {
13-
return "ApiException(statusCode=$statusCode, errorCode=$errorCode, details=$details)"
13+
return "ApiException(statusCode=$statusCode, code=$code, details=$details, message=$message)"
1414
}
1515
}

src/main/kotlin/com/github/mduesterhoeft/router/RequestHandler.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
5858
input, ApiException(
5959
statusCode = 415,
6060
message = "Unsupported Media Type",
61-
errorCode = 1
61+
code = "UNSUPPORTED_MEDIA_TYPE"
6262
)
6363
)
6464
}
@@ -67,7 +67,7 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
6767
input, ApiException(
6868
statusCode = 406,
6969
message = "Not Acceptable",
70-
errorCode = 2
70+
code = "NOT_ACCEPTABLE"
7171
)
7272
)
7373
}
@@ -76,15 +76,15 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
7676
input, ApiException(
7777
statusCode = 405,
7878
message = "Method Not Allowed",
79-
errorCode = 3
79+
code = "METHOD_NOT_ALLOWED"
8080
)
8181
)
8282
}
8383
return createErrorResponse(
8484
input, ApiException(
8585
statusCode = 404,
8686
message = "Not found",
87-
errorCode = 4
87+
code = "NOT_FOUND"
8888
)
8989
)
9090
}
@@ -95,7 +95,7 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
9595
APIGatewayProxyResponseEvent()
9696
.withBody(objectMapper.writeValueAsString(mapOf(
9797
"message" to ex.message,
98-
"code" to ex.errorCode,
98+
"code" to ex.code,
9999
"details" to ex.details
100100
)))
101101
.withStatusCode(ex.statusCode)

0 commit comments

Comments
 (0)