• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala HttpErrorHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ErrorHandler

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

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

import com.sharecare.lib.play.errors.Error
import play.api.libs.json.Json

@Singleton
class ErrorHandler extends HttpErrorHandler {
  import com.sharecare.lib.play.errors.serialization.ErrorJsonFormats._

  def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    Future.successful(
      statusCode match {
        case 400 => BadRequest(Json.toJson(Error(message, Some(statusCode))))
        case 401 => Unauthorized(Json.toJson(Error(message, Some(statusCode))))
        case 404 => NotFound(Json.toJson(Error(message, Some(statusCode))))
        case _   => InternalServerError(Json.toJson(Error(message, Some(statusCode))))
      }

    )
  }

  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError(Json.toJson(Error("A server error occurred: " + exception.getMessage, Some(500))))
    )
  }
} 
开发者ID:Sharecare,项目名称:health-profile-social-history-play,代码行数:33,代码来源:ErrorHandler.scala


示例17: environment

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

import play.api.{ Configuration, Environment }
import play.api.http.HttpErrorHandler
import play.api.routing.Router
import play.core.SourceMapper
import play.filters.csrf.{ CSRFConfig, CSRFFilter }
import play.filters.headers.SecurityHeadersFilter

import com.softwaremill.macwire._

import com.github.jacobono.utils._

trait UtilModule {
  def environment: Environment
  def configuration: Configuration
  def sourceMapper: Option[SourceMapper]
  def routerOption: Option[Router]
  def csrfFilter: CSRFFilter
  def csrfConfig: CSRFConfig
  def securityHeadersFilter: SecurityHeadersFilter

  lazy val filters = wire[Filters]
  lazy val csrfHelper = wire[CSRFHelper]

  lazy val errorHandler: HttpErrorHandler = wire[ErrorHandler]
} 
开发者ID:jacobono,项目名称:silhouette-macwire,代码行数:28,代码来源:UtilModule.scala


示例18: ErrorHandler

//设置package包名称以及导入依赖的类
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 404 => Future.successful(Status(statusCode)( statusCode  + " - Page not found "  ))
    }
  }
  def onServerError(request: RequestHeader, exception: Throwable) = {
    Future.successful(
      InternalServerError("A server error occurred: " + exception.getMessage)
    )
  }
} 
开发者ID:anmol2709,项目名称:Test-Play-Assignment,代码行数:21,代码来源:ErrorHandler.scala


示例19: get

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

import javax.inject.{ Inject, Singleton }

import play.api.Environment
import play.api.http.HttpErrorHandler
import play.api.mvc.{ Action, AnyContent }

trait AssetCtrl {
  def get(file: String): Action[AnyContent]
}

@Singleton
class AssetCtrlProd @Inject() (errorHandler: HttpErrorHandler) extends Assets(errorHandler) with AssetCtrl {
  def get(file: String): Action[AnyContent] = at("/ui", file)
}

@Singleton
class AssetCtrlDev @Inject() (environment: Environment) extends ExternalAssets(environment) with AssetCtrl {
  def get(file: String): Action[AnyContent] = {
    if (file.startsWith("bower_components/")) {
      at("ui", file)
    }
    else {
      at("ui/app", file)
    }
  }
} 
开发者ID:CERT-BDF,项目名称:Cortex,代码行数:29,代码来源:Asset.scala


示例20: ErrorHandler

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

import models.{ AnalyzerNotFoundError, InvalidRequestError, JobNotFoundError, UnexpectedError }
import play.api.Logger
import play.api.http.HttpErrorHandler
import play.api.mvc.{ RequestHeader, Result, Results }

import scala.concurrent.Future

class ErrorHandler extends HttpErrorHandler {
  private[ErrorHandler] lazy val logger = Logger(getClass)
  def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result] = Future.successful {
    Results.Status(statusCode)(s"A client error occurred on ${request.method} ${request.uri} : $message")
  }

  def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
    val result = exception match {
      case JobNotFoundError(jobId)           ? Results.NotFound(s"Job $jobId not found")
      case UnexpectedError(message)          ? Results.InternalServerError(message)
      case AnalyzerNotFoundError(analyzerId) ? Results.NotFound(s"analyzer $analyzerId not found")
      case InvalidRequestError(message)      ? Results.BadRequest(message)
      case error                             ? Results.InternalServerError(s"Unexpected error: $error")
    }
    Logger.info(s"${request.method} ${request.uri} returned ${result.header.status}", exception)
    Future.successful(result)
  }
} 
开发者ID:CERT-BDF,项目名称:Cortex,代码行数:28,代码来源:ErrorHandler.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ImplementedBy类代码示例发布时间:2022-05-23
下一篇:
Scala exp类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap