2017-07-25 61 views
0

在我的倉庫功能,我讀一個用戶,然後更新該用戶:如何在spray/akka中手動拋出HTTP 404 Not Found異常?

def update(u: User): Future[Int] = { 
    this.read(u.id).flatMap { 
     case Some(existingUser) => 
     db.run(
      userTable 
      .filter(_.id === user.id) 
      .update(user.copy(createdDate = existingUser.createdDate))) 
     //case None => throw new NotFoundException(); // does this exception exist in spray/akka? 
    } 
} 

我想拋出某種異常的位置,當用戶沒有找到,從而使噴塗/阿卡意志知道異常意味着返回HTTP 404 Not Found。

spray/akka是否包含某種我可以手動拋出的NotFoundException?

回答

1

是否有是個例外,或者您可以使用此:

 case None => HttpResponse(StatusCodes.NotFound) 
相關問題