feat: パスワード、ユーザー名が間違っているときに正常なHTTP Status Codeを返すように

This commit is contained in:
usbharu 2023-05-01 10:48:59 +09:00
parent bf6fe19ede
commit 96c54d26fd
4 changed files with 10 additions and 13 deletions

View File

@ -41,6 +41,10 @@ tasks.withType<ShadowJar> {
}
}
tasks.clean {
delete += listOf("$rootDir/src/main/resources/static")
}
repositories {
mavenCentral()
}

View File

@ -1,14 +1,8 @@
package dev.usbharu.hideout.exception
class UserNotFoundException : Exception {
class UserNotFoundException : IllegalArgumentException {
constructor() : super()
constructor(message: String?) : super(message)
constructor(s: String?) : super(s)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
constructor(
message: String?,
cause: Throwable?,
enableSuppression: Boolean,
writableStackTrace: Boolean
) : super(message, cause, enableSuppression, writableStackTrace)
}

View File

@ -7,11 +7,11 @@ import io.ktor.server.response.*
fun Application.configureStatusPages() {
install(StatusPages) {
exception<Throwable> { call, cause ->
call.respondText(text = "500: $cause", status = HttpStatusCode.InternalServerError)
}
exception<IllegalArgumentException> { call, cause ->
call.respondText(text = "400: $cause", status = HttpStatusCode.BadRequest)
}
exception<Throwable> { call, cause ->
call.respondText(text = "500: $cause", status = HttpStatusCode.InternalServerError)
}
}
}

View File

@ -1,7 +1,6 @@
package dev.usbharu.hideout.service.impl
import dev.usbharu.hideout.config.Config
import dev.usbharu.hideout.exception.UserNotFoundException
import dev.usbharu.hideout.repository.IUserRepository
import dev.usbharu.hideout.service.IUserAuthService
import io.ktor.util.*
@ -24,7 +23,7 @@ class UserAuthService(
override suspend fun verifyAccount(username: String, password: String): Boolean {
val userEntity = userRepository.findByNameAndDomain(username, Config.configData.domain)
?: throw UserNotFoundException("$username was not found")
?: return false
return userEntity.password == hash(password)
}