Improved exception handling

This commit is contained in:
2025-08-26 14:21:47 -04:00
parent 0f0babe8da
commit f3714b9a18

View File

@@ -39,10 +39,15 @@ fun Application.configureLoginRoutes(dbConnection: Connection) {
call.respond(HttpStatusCode.OK, mapOf("token" to token)) call.respond(HttpStatusCode.OK, mapOf("token" to token))
} }
else { 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) { } 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}"))
} }
} }