Add InvalidCredentialError

This commit is contained in:
Hubert Van De Walle 2020-04-12 01:35:35 +02:00
parent 09643eca0c
commit 542eaa21cc
2 changed files with 9 additions and 2 deletions

View File

@ -2,7 +2,9 @@ package be.vandewalleh.controllers
import be.vandewalleh.auth.SimpleJWT import be.vandewalleh.auth.SimpleJWT
import be.vandewalleh.auth.UsernamePasswordCredential import be.vandewalleh.auth.UsernamePasswordCredential
import be.vandewalleh.errors.ApiError
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.Location import io.ktor.locations.Location
import io.ktor.locations.post import io.ktor.locations.post
import io.ktor.request.receive import io.ktor.request.receive
@ -20,9 +22,9 @@ class UserController(kodein: Kodein) : KodeinController(kodein) {
// TODO check db // TODO check db
if (post.username != "test" || post.password != "test") 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")))
} }
} }

5
api/src/errors/Errors.kt Normal file
View File

@ -0,0 +1,5 @@
package be.vandewalleh.errors
sealed class ApiError(val message: String){
class InvalidCredentialError : ApiError("Invalid credentials")
}