当前位置: 首页>>代码示例>>Scala>>正文


Scala HttpErrorHandler类代码示例

本文整理汇总了Scala中play.api.http.HttpErrorHandler的典型用法代码示例。如果您正苦于以下问题:Scala HttpErrorHandler类的具体用法?Scala HttpErrorHandler怎么用?Scala HttpErrorHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HttpErrorHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: ErrorHandler

//设置package包名称以及导入依赖的类
package utils.auth
import play.api.http.HttpErrorHandler
import play.api.mvc._
import play.api.mvc.Results._
import scala.concurrent._

class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    Future.successful(
      Status(statusCode)("A client error occurred: " + message)
    )
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }
} 
开发者ID:Bakuchi,项目名称:certification,代码行数:21,代码来源:ErrorHandler.scala

示例2: ErrorHandler

//设置package包名称以及导入依赖的类
package walfie.gbf.raidfinder.server

import play.api.http.HttpErrorHandler
import play.api.libs.json._
import play.api.mvc._
import play.api.mvc.Results._
import scala.concurrent.Future

class ErrorHandler extends HttpErrorHandler {
  // TODO: Make this more structured
  private def jsonResponse(statusCode: Int, message: String): JsObject =
    Json.obj(
      "errors" -> Json.arr(
        Json.obj(
          "status" -> statusCode,
          "detail" -> message
        )
      )
    )

  def onClientError(
    request:    RequestHeader,
    statusCode: Int,
    message:    String
  ): Future[Result] = Future.successful {
    Status(statusCode)(jsonResponse(statusCode, message))
  }

  def onServerError(
    request:   RequestHeader,
    exception: Throwable
  ): Future[Result] = Future.successful {
    InternalServerError(jsonResponse(500, "Internal server error"))
  }
} 
开发者ID:walfie,项目名称:gbf-raidfinder,代码行数:36,代码来源:ErrorHandler.scala

示例3: ErrorHandler

//设置package包名称以及导入依赖的类
import play.api.http.HttpErrorHandler
import play.api.mvc._
import play.api.mvc.Results._
import scala.concurrent._
import javax.inject.Singleton;

@Singleton
class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    Future.successful(
      statusCode match {
        case 400=> Ok(views.html.error(" Oops!!!! BAD REQUEST"))
        case 401=> Ok(views.html.error(" Oops!!!! UNAUTHORIZED"))
        case 404=> Ok(views.html.error("Oops!!!! Page not Found"))
        case 500=> Ok(views.html.error(" Oops!!!! Internal Server Error"))
      }
    )
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }
} 
开发者ID:SHUB9914,项目名称:AjaxPlay-SHUBHAM,代码行数:27,代码来源:ErrorHandler.scala

示例4: ErrorHandler

//设置package包名称以及导入依赖的类
package common

import org.slf4j.MDC
import play.api.Logger
import play.api.http.HttpErrorHandler
import play.api.libs.json.Json
import play.api.mvc.Results._
import play.api.mvc.{Result, RequestHeader}

import scala.concurrent.Future
import scala.util.Try

class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, m: String): Future[Result] = {
    val message = if(m.isEmpty) "there was a problem in the request, please check the path and the headers" else m
    Logger.warn(s"There was a client error with statusCode $statusCode in ${request.method} ${request.path} with message: $message")
    Future.successful(Status(statusCode)(Json.obj("error" -> true, "message" -> message)))
  }

  def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
    val requestId = Try(MDC.get("requestId")).getOrElse{Logger.warn("couldnt get the requestId from MDC");""}
    val message = s"There was a server error in ${request.method} ${request.path} with requestId $requestId"
    Logger.error(message, exception)
    Future.successful(InternalServerError(Json.obj("error" -> true, "message" -> exception.getMessage)))
  }

} 
开发者ID:dtambussi,项目名称:pedidos,代码行数:29,代码来源:ErrorHandler.scala

示例5: ErrorHandler

//设置package包名称以及导入依赖的类
import play.api.{Logger, mvc}
import play.api.http.HttpErrorHandler
import play.api.mvc._
import play.api.mvc.Results._

import scala.concurrent._
import play.api.Play.current
import play.api.i18n.Messages.Implicits._
class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    val fullMessage = "An error occurred: " + statusCode + (if (message.nonEmpty) ", " + message else "")
    Logger.logger.error(fullMessage)
    Future.successful(
      Status(statusCode)(views.html.error(fullMessage))
    )
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Logger.logger.error("A server error occurred: " + exception.getMessage, exception)
    Future.successful(
      InternalServerError(views.html.error("A server error occurred: " + exception.getMessage))
    )
  }
} 
开发者ID:intracer,项目名称:wlxjury,代码行数:26,代码来源:ErrorHandler.scala

示例6: ErrorHandler

//设置package包名称以及导入依赖的类
import play.api.http.HttpErrorHandler
import play.api.mvc._
import play.api.mvc.Results._

import scala.concurrent._
import javax.inject.Singleton

import controllers.routes;

@Singleton
class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    statusCode match {
      case 404 => Future.successful(Status(statusCode)("Page Not Found Error"))
      case 400 => Future.successful(Redirect(routes.LoginController.index()))
      case _ => Future.successful(BadRequest)
    }
  }
  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }
} 
开发者ID:kunals201,项目名称:play2-assignment-kunal-testcases,代码行数:26,代码来源:Error.scala

示例7: ErrorHandler

//设置package包名称以及导入依赖的类
import scala.concurrent._

import play.api.Logger
import play.api.http.HttpErrorHandler
import play.api.mvc.RequestHeader
import play.api.mvc.Results.{InternalServerError, Status}

class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    Logger.error(s"${request.method} ${request.uri} returned $statusCode - $message")
    Future.successful(
      Status(statusCode)(message)
    )
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError(exception.getMessage)
    )
  }
} 
开发者ID:sebtomba,项目名称:wordcount-akka-streams,代码行数:23,代码来源:ErrorHandler.scala

示例8: ErrorHandler

//设置package包名称以及导入依赖的类
package services

import scala.concurrent._
import javax.inject._
import play.api.http.HttpErrorHandler
import play.api.libs.json._
import play.api.mvc.Results._
import play.api.mvc._

@Singleton
class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    statusCode match {
      case 404 =>
        Future.successful (
          Status (statusCode) (Json.obj ("status" -> "error", "message" -> "Not Found") )
        )
      case _ =>
        Future.successful (
          Status (statusCode) (Json.obj ("status" -> "error", "message" -> message) )
        )
    }
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError(Json.obj("status" -> "error", "message" -> exception.getMessage))
    )
  }
} 
开发者ID:panggi,项目名称:pujangga,代码行数:32,代码来源:ErrorHandler.scala

示例9: Handler

//设置package包名称以及导入依赖的类
package org.birdfeed.chirp.errors

import com.google.inject.Singleton
import org.postgresql.util.PSQLException
import play.api.http.HttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._

import scala.concurrent._

@Singleton
class Handler extends HttpErrorHandler with JsonError {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    Future.successful(
      Status(statusCode)("A client error occurred: " + message)
    )
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(exception match {
      case ex: PSQLException => {
        BadRequest(jsonException("A database error has occurred.", ex))
      }
        // TODO: Fix this
//      case ex: AuthenticationFailedException => {
//        Unauthorized(jsonException("Invalid credentials.", ex))
//      }
      case ex: Exception => {
        InternalServerError(jsonException("An ISE has occurred.", ex))
    }})
  }
} 
开发者ID:AwesomeIT,项目名称:chirp,代码行数:34,代码来源:Handler.scala

示例10: AppErrorHandler

//设置package包名称以及导入依赖的类
package utilities

import play.api.http.HttpErrorHandler
import play.api.mvc._
import play.api.mvc.Results._
import scala.concurrent._
import play.Logger

class AppErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    Logger.debug("onClientError")
    Logger.debug(request.toString())
    Logger.debug(statusCode.toString())
    Logger.debug(message)
    Future.successful(
        //Ok(errors.views.html.404notfound())
      //Status(statusCode)("A client error occurred: " + message)
      Status(statusCode)(views.html.errors.error404notfound(message))
    )
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Logger.debug("server error")
    Logger.debug(request.toString())
    Logger.debug(exception.getMessage)
    Logger.debug(exception.toString())
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }
} 
开发者ID:bananapianist,项目名称:playfw_sample,代码行数:33,代码来源:AppErrorHandler.scala

示例11: RegExCORSFilter

//设置package包名称以及导入依赖的类
package com.github.dgilling.regexcors

import akka.stream.Materializer
import play.api.Logger
import play.api.http.{DefaultHttpErrorHandler, HttpErrorHandler}
import play.api.mvc.{Result, RequestHeader, Filter}
import play.core.j.JavaHttpErrorHandlerAdapter
import play.filters.cors.{CORSFilter, AbstractCORSPolicy, CORSConfig}

import scala.concurrent.Future


class RegExCORSFilter(
                  override protected val corsConfig: CORSConfig = CORSConfig(),
                  override protected val errorHandler: HttpErrorHandler = DefaultHttpErrorHandler,
                  private val pathPrefixes: Seq[String] = Seq("/"),
                  private val ignoredPathPrefixes: Seq[String] = Seq.empty[String])(override implicit val mat: Materializer)
  extends CORSFilter {

  // Java constructor
  def this(corsConfig: CORSConfig, errorHandler: play.http.HttpErrorHandler, pathPrefixes: java.util.List[String])(mat: Materializer) = {
    this(corsConfig, new JavaHttpErrorHandlerAdapter(errorHandler), Seq(pathPrefixes.toArray.asInstanceOf[Array[String]]: _*))(mat)
  }

  override protected val logger = Logger(classOf[CORSFilter])

  override def apply(f: RequestHeader => Future[Result])(request: RequestHeader): Future[Result] = {
    if (pathPrefixes.exists(request.path.startsWith) &&
      !ignoredPathPrefixes.exists(request.path.startsWith)) {
      filterRequest(f, request)
    } else {
      f(request)
    }
  }
}

object RegExCORSFilter {

  val RequestTag = "CORS_REQUEST"

  def apply(corsConfig: CORSConfig = CORSConfig(), errorHandler: HttpErrorHandler = DefaultHttpErrorHandler,
            pathPrefixes: Seq[String] = Seq("/"))(implicit mat: Materializer) =
    new CORSFilter(corsConfig, errorHandler, pathPrefixes)

} 
开发者ID:dgilling,项目名称:play-regex-cors,代码行数:46,代码来源:RegExCORSFilter.scala

示例12: ErrorHandler

//设置package包名称以及导入依赖的类
import java.lang.ProcessBuilder
import controllers.routes
import play.api.http.HttpErrorHandler
import play.api.mvc._
import play.api.mvc.Results._
import scala.concurrent._
import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.Future

class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    statusCode match {
      case 400 => Future.successful(Status(statusCode)( statusCode + "-Bad Request !!!!!!!"))
      case 404 => Future.successful(Status(statusCode)( statusCode + "-Page not found !!!!!!!"))
      case 401 => Future.successful(Status(statusCode)( statusCode + "-Unauthorized !!!!!!!"))

    }
  }
  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      Redirect(routes.HomeController.signUp()).flashing(
        "error" -> "Please check Values")
    )
  }
} 
开发者ID:anmol2709,项目名称:Play-Assignment-01,代码行数:27,代码来源:ErrorHandle.scala

示例13: ErrorHandler

//设置package包名称以及导入依赖的类
package util

import javax.inject.Singleton

import play.api.http.HttpErrorHandler
import play.api.mvc.{RequestHeader, Result, Results}

import scala.concurrent.Future


@Singleton
class ErrorHandler extends HttpErrorHandler{
  override def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result] = {
    Future.successful(
      Results.Status(statusCode)("A client error occurred: " + message)
    )
  }

  override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
    Future.successful(
      Results.InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }
} 
开发者ID:xiren,项目名称:Apollo,代码行数:25,代码来源:ErrorHandler.scala

示例14: RequestHandler

//设置package包名称以及导入依赖的类
package ylabs.play.common

import javax.inject.Inject

import play.api.http.{DefaultHttpRequestHandler, HttpConfiguration, HttpErrorHandler, HttpFilters}
import play.api.mvc.{Handler, RequestHeader}
import play.api.routing.Router
import ylabs.play.common.controllers.{FileUploadController, HealthcheckController, LocationController, UserController}

class RequestHandler @Inject() (
  router: Router,
  errorHandler: HttpErrorHandler,
  configuration: HttpConfiguration,
  filters: HttpFilters,
  userController: UserController,
  locationController: LocationController,
  fileUploadController: FileUploadController,
  healthcheckController: HealthcheckController
  ) extends DefaultHttpRequestHandler(router , errorHandler, configuration, filters) {

  override def routeRequest(req: RequestHeader): Option[Handler] = {
    (req.method, req.path) match {
      case ("GET", "/auth") ? Some(userController.authenticate())
      case ("POST", "/user") ? Some(userController.create())
      case ("POST", "/user/code/request") => Some(userController.requestCode())
      case ("POST", "/user/code/register") => Some(userController.registerDevice())
      case ("PATCH", "/user") ? Some(userController.update())
      case ("GET", "/user") ? Some(userController.get())
      case ("POST", "/location") ? Some(locationController.update())
      case ("GET", "/location") ? Some(locationController.list())
      case ("GET", "/location/last") ? Some(locationController.last())
      case ("POST", "/location/nearby") ? Some(locationController.nearby())
      case ("POST", "/location/suggest") ? Some(locationController.suggest())
      case ("POST", "/cloud") ? Some(fileUploadController.uploadFile())
      case ("GET", "/healthcheck") ? Some(healthcheckController.check())
      case _ ? None
    }
  }
} 
开发者ID:springnz,项目名称:play-app-base,代码行数:40,代码来源:RequestHandler.scala

示例15: ErrorHandler

//设置package包名称以及导入依赖的类
package application.services.common

import play.api.http.HttpErrorHandler
import play.api.mvc._
import play.api.mvc.Results._
import scala.concurrent._
import javax.inject.Singleton;

@Singleton
class ErrorHandler extends HttpErrorHandler {

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {

    if(statusCode == play.api.http.Status.NOT_FOUND) {
      // Not Found
      Future.successful(Ok("???????????????????????"))
    } else {
      // otherwise
      Future.successful(
        Status(statusCode)("A client error occurred: " + message)
      )
    }
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }
} 
开发者ID:louvre2489,项目名称:RoomReservation,代码行数:31,代码来源:ErrorHandler.scala


注:本文中的play.api.http.HttpErrorHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。