diff --git a/api/src/controllers/UserController.kt b/api/src/controllers/UserController.kt index 700df0a..717be2a 100644 --- a/api/src/controllers/UserController.kt +++ b/api/src/controllers/UserController.kt @@ -2,7 +2,9 @@ package be.vandewalleh.controllers import be.vandewalleh.auth.SimpleJWT import be.vandewalleh.auth.UsernamePasswordCredential +import be.vandewalleh.errors.ApiError import io.ktor.application.call +import io.ktor.http.HttpStatusCode import io.ktor.locations.Location import io.ktor.locations.post import io.ktor.request.receive @@ -20,9 +22,9 @@ class UserController(kodein: Kodein) : KodeinController(kodein) { // TODO check db if (post.username != "test" || post.password != "test") - error("Invalid Credentials") + return@post call.respond(HttpStatusCode.BadRequest, ApiError.InvalidCredentialError()) - call.respond(mapOf("token" to simpleJwt.sign("test@test.be"))) + return@post call.respond(mapOf("token" to simpleJwt.sign("test@test.be"))) } } diff --git a/api/src/errors/Errors.kt b/api/src/errors/Errors.kt new file mode 100644 index 0000000..8363139 --- /dev/null +++ b/api/src/errors/Errors.kt @@ -0,0 +1,5 @@ +package be.vandewalleh.errors + +sealed class ApiError(val message: String){ + class InvalidCredentialError : ApiError("Invalid credentials") +}