mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-07-12 13:25:51 +00:00
rejection handling
This commit is contained in:
27
src/main/resources/logback-application.xml
Normal file
27
src/main/resources/logback-application.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<included>
|
||||||
|
|
||||||
|
<appender name="application-base" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%-5level %d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%logger{50}]: %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
|
||||||
|
<file>application.log</file>
|
||||||
|
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||||
|
<minIndex>1</minIndex>
|
||||||
|
<maxIndex>20</maxIndex>
|
||||||
|
<fileNamePattern>application.log.%i.gz</fileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||||
|
<maxFileSize>100MB</maxFileSize>
|
||||||
|
</triggeringPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="application" class="ch.qos.logback.classic.AsyncAppender">
|
||||||
|
<appender-ref ref="application-base"/>
|
||||||
|
<queueSize>50000</queueSize>
|
||||||
|
<neverBlock>true</neverBlock>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
</included>
|
27
src/main/resources/logback-http.xml
Normal file
27
src/main/resources/logback-http.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<included>
|
||||||
|
|
||||||
|
<appender name="http-base" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %marker %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
|
||||||
|
<file>http.log</file>
|
||||||
|
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||||
|
<minIndex>1</minIndex>
|
||||||
|
<maxIndex>20</maxIndex>
|
||||||
|
<fileNamePattern>http.log.%i.gz</fileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||||
|
<maxFileSize>100MB</maxFileSize>
|
||||||
|
</triggeringPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="http" class="ch.qos.logback.classic.AsyncAppender">
|
||||||
|
<appender-ref ref="http-base"/>
|
||||||
|
<queueSize>50000</queueSize>
|
||||||
|
<neverBlock>true</neverBlock>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
</included>
|
@ -1,5 +1,13 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
|
<include resource="logback-application.xml" />
|
||||||
|
<include resource="logback-http.xml" />
|
||||||
|
|
||||||
|
<root level="debug">
|
||||||
|
<appender-ref ref="application" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<logger name="me.arcanis.ffxivbis" level="DEBUG" />
|
||||||
<logger name="slick.jdbc.JdbcBackend.statement" level="DEBUG" />
|
<logger name="slick.jdbc.JdbcBackend.statement" level="DEBUG" />
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -29,7 +29,7 @@ import scala.util.{Failure, Success}
|
|||||||
|
|
||||||
@Path("api/v1")
|
@Path("api/v1")
|
||||||
class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit timeout: Timeout)
|
class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit timeout: Timeout)
|
||||||
extends BiSHelper(storage, ariyala) with Authorization with JsonSupport with HttpExceptionsHandler {
|
extends BiSHelper(storage, ariyala) with Authorization with JsonSupport with HttpHandler {
|
||||||
|
|
||||||
def route: Route = createBiS ~ getBiS ~ modifyBiS
|
def route: Route = createBiS ~ getBiS ~ modifyBiS
|
||||||
|
|
||||||
@ -55,6 +55,7 @@ class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit ti
|
|||||||
def createBiS: Route =
|
def createBiS: Route =
|
||||||
path("party" / Segment / "bis") { partyId =>
|
path("party" / Segment / "bis") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
||||||
put {
|
put {
|
||||||
@ -70,6 +71,7 @@ class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit ti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("party/{partyId}/bis")
|
@Path("party/{partyId}/bis")
|
||||||
@ -95,6 +97,7 @@ class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit ti
|
|||||||
def getBiS: Route =
|
def getBiS: Route =
|
||||||
path("party" / Segment / "bis") { partyId =>
|
path("party" / Segment / "bis") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
||||||
get {
|
get {
|
||||||
@ -107,6 +110,8 @@ class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit ti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,6 +138,7 @@ class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit ti
|
|||||||
def modifyBiS: Route =
|
def modifyBiS: Route =
|
||||||
path("party" / Segment / "bis") { partyId =>
|
path("party" / Segment / "bis") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
||||||
post {
|
post {
|
||||||
@ -149,3 +155,4 @@ class BiSEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit ti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package me.arcanis.ffxivbis.http.api.v1
|
|
||||||
|
|
||||||
import akka.http.scaladsl.model.StatusCodes
|
|
||||||
import akka.http.scaladsl.server.Directives._
|
|
||||||
import akka.http.scaladsl.server._
|
|
||||||
import com.typesafe.scalalogging.StrictLogging
|
|
||||||
import me.arcanis.ffxivbis.http.api.v1.json._
|
|
||||||
|
|
||||||
trait HttpExceptionsHandler extends StrictLogging { this: JsonSupport =>
|
|
||||||
|
|
||||||
def exceptionHandler: ExceptionHandler = ExceptionHandler {
|
|
||||||
case other: Exception =>
|
|
||||||
logger.error("exception during request completion", other)
|
|
||||||
complete(StatusCodes.InternalServerError, ErrorResponse("unknown server error"))
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,26 @@
|
|||||||
|
package me.arcanis.ffxivbis.http.api.v1
|
||||||
|
|
||||||
|
import akka.http.scaladsl.model._
|
||||||
|
import akka.http.scaladsl.server.Directives._
|
||||||
|
import akka.http.scaladsl.server._
|
||||||
|
import com.typesafe.scalalogging.StrictLogging
|
||||||
|
import me.arcanis.ffxivbis.http.api.v1.json._
|
||||||
|
import spray.json._
|
||||||
|
|
||||||
|
trait HttpHandler extends StrictLogging { this: JsonSupport =>
|
||||||
|
|
||||||
|
implicit def exceptionHandler: ExceptionHandler = ExceptionHandler {
|
||||||
|
case other: Exception =>
|
||||||
|
logger.error("exception during request completion", other)
|
||||||
|
complete(StatusCodes.InternalServerError, ErrorResponse("unknown server error"))
|
||||||
|
}
|
||||||
|
|
||||||
|
implicit def rejectionHandler: RejectionHandler =
|
||||||
|
RejectionHandler.default
|
||||||
|
.mapRejectionResponse {
|
||||||
|
case response @ HttpResponse(_, _, entity: HttpEntity.Strict, _) =>
|
||||||
|
val message = ErrorResponse(entity.data.utf8String).toJson
|
||||||
|
response.copy(entity = HttpEntity(ContentTypes.`application/json`, message.compactPrint))
|
||||||
|
case other => other
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ import scala.util.{Failure, Success}
|
|||||||
|
|
||||||
@Path("api/v1")
|
@Path("api/v1")
|
||||||
class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
||||||
extends LootHelper(storage) with Authorization with JsonSupport with HttpExceptionsHandler {
|
extends LootHelper(storage) with Authorization with JsonSupport with HttpHandler {
|
||||||
|
|
||||||
def route: Route = getLoot ~ modifyLoot
|
def route: Route = getLoot ~ modifyLoot
|
||||||
|
|
||||||
@ -56,6 +56,7 @@ class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
def getLoot: Route =
|
def getLoot: Route =
|
||||||
path("party" / Segment / "loot") { partyId =>
|
path("party" / Segment / "loot") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
||||||
get {
|
get {
|
||||||
@ -71,6 +72,7 @@ class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes(value = Array("application/json"))
|
@Consumes(value = Array("application/json"))
|
||||||
@ -94,6 +96,7 @@ class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
def modifyLoot: Route =
|
def modifyLoot: Route =
|
||||||
path("party" / Segment / "loot") { partyId =>
|
path("party" / Segment / "loot") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
||||||
post {
|
post {
|
||||||
@ -109,6 +112,7 @@ class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("party/{partyId}/loot")
|
@Path("party/{partyId}/loot")
|
||||||
@ -136,6 +140,7 @@ class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
def suggestLoot: Route =
|
def suggestLoot: Route =
|
||||||
path("party" / Segment / "loot") { partyId =>
|
path("party" / Segment / "loot") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
||||||
put {
|
put {
|
||||||
@ -151,3 +156,4 @@ class LootEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -28,7 +28,7 @@ import scala.util.{Failure, Success}
|
|||||||
|
|
||||||
@Path("api/v1")
|
@Path("api/v1")
|
||||||
class PlayerEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit timeout: Timeout)
|
class PlayerEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit timeout: Timeout)
|
||||||
extends PlayerHelper(storage, ariyala) with Authorization with JsonSupport with HttpExceptionsHandler {
|
extends PlayerHelper(storage, ariyala) with Authorization with JsonSupport with HttpHandler {
|
||||||
|
|
||||||
def route: Route = getParty ~ modifyParty
|
def route: Route = getParty ~ modifyParty
|
||||||
|
|
||||||
@ -56,6 +56,7 @@ class PlayerEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit
|
|||||||
def getParty: Route =
|
def getParty: Route =
|
||||||
path("party" / Segment) { partyId =>
|
path("party" / Segment) { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
|
||||||
get {
|
get {
|
||||||
@ -71,6 +72,7 @@ class PlayerEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("party/{partyId}")
|
@Path("party/{partyId}")
|
||||||
@ -94,6 +96,7 @@ class PlayerEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit
|
|||||||
def modifyParty: Route =
|
def modifyParty: Route =
|
||||||
path("party" / Segment) { partyId =>
|
path("party" / Segment) { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authPost(partyId)) { _ =>
|
||||||
entity(as[PlayerActionResponse]) { action =>
|
entity(as[PlayerActionResponse]) { action =>
|
||||||
@ -108,3 +111,4 @@ class PlayerEndpoint(override val storage: ActorRef, ariyala: ActorRef)(implicit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -28,7 +28,7 @@ import scala.util.{Failure, Success}
|
|||||||
|
|
||||||
@Path("api/v1")
|
@Path("api/v1")
|
||||||
class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
||||||
extends UserHelper(storage) with Authorization with JsonSupport with HttpExceptionsHandler {
|
extends UserHelper(storage) with Authorization with JsonSupport with HttpHandler {
|
||||||
|
|
||||||
def route: Route = createParty ~ createUser ~ deleteUser ~ getUsers
|
def route: Route = createParty ~ createUser ~ deleteUser ~ getUsers
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
def createParty: Route =
|
def createParty: Route =
|
||||||
path("party" / Segment / "create") { partyId =>
|
path("party" / Segment / "create") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
put {
|
put {
|
||||||
entity(as[UserResponse]) { user =>
|
entity(as[UserResponse]) { user =>
|
||||||
@ -65,6 +66,7 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("party/{partyId}/users")
|
@Path("party/{partyId}/users")
|
||||||
@ -88,6 +90,7 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
def createUser: Route =
|
def createUser: Route =
|
||||||
path("party" / Segment / "users") { partyId =>
|
path("party" / Segment / "users") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authAdmin(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authAdmin(partyId)) { _ =>
|
||||||
post {
|
post {
|
||||||
@ -103,6 +106,7 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("party/{partyId}/users/{username}")
|
@Path("party/{partyId}/users/{username}")
|
||||||
@ -123,6 +127,7 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
def deleteUser: Route =
|
def deleteUser: Route =
|
||||||
path("party" / Segment / "users" / Segment) { (partyId, username) =>
|
path("party" / Segment / "users" / Segment) { (partyId, username) =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authAdmin(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authAdmin(partyId)) { _ =>
|
||||||
delete {
|
delete {
|
||||||
@ -135,6 +140,7 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("party/{partyId}/users")
|
@Path("party/{partyId}/users")
|
||||||
@ -158,6 +164,7 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
def getUsers: Route =
|
def getUsers: Route =
|
||||||
path("party" / Segment / "users") { partyId =>
|
path("party" / Segment / "users") { partyId =>
|
||||||
handleExceptions(exceptionHandler) {
|
handleExceptions(exceptionHandler) {
|
||||||
|
handleRejections(rejectionHandler) {
|
||||||
extractExecutionContext { implicit executionContext =>
|
extractExecutionContext { implicit executionContext =>
|
||||||
authenticateBasicBCrypt(s"party $partyId", authAdmin(partyId)) { _ =>
|
authenticateBasicBCrypt(s"party $partyId", authAdmin(partyId)) { _ =>
|
||||||
get {
|
get {
|
||||||
@ -171,3 +178,4 @@ class UserEndpoint(override val storage: ActorRef)(implicit timeout: Timeout)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user