Improved exception handling
This commit is contained in:
@@ -39,10 +39,15 @@ fun Application.configureLoginRoutes(dbConnection: Connection) {
|
||||
call.respond(HttpStatusCode.OK, mapOf("token" to token))
|
||||
}
|
||||
else {
|
||||
call.respond(HttpStatusCode.Unauthorized, "Invalid login")
|
||||
log.error("Unauthorized use: $name")
|
||||
call.respond(HttpStatusCode.Unauthorized, mapOf("message" to "Invalid login", "User" to user.name))
|
||||
}
|
||||
} catch (cause: DbElementNotFoundException) {
|
||||
call.respond(HttpStatusCode.BadRequest, cause.message ?: "Something went wrong")
|
||||
log.error(cause.message)
|
||||
call.respond(HttpStatusCode.BadRequest, mapOf("message" to cause.message))
|
||||
} catch (cause: Exception) {
|
||||
log.error(cause.message)
|
||||
call.respond(HttpStatusCode.BadRequest, mapOf("message" to "An unexpected error occurred: ${cause.message}"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user