Add InvalidCredentialError
This commit is contained in:
parent
09643eca0c
commit
542eaa21cc
@ -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")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
5
api/src/errors/Errors.kt
Normal file
5
api/src/errors/Errors.kt
Normal file
@ -0,0 +1,5 @@
|
||||
package be.vandewalleh.errors
|
||||
|
||||
sealed class ApiError(val message: String){
|
||||
class InvalidCredentialError : ApiError("Invalid credentials")
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user