2016-04-13 41 views
0

Ben sessizce herhangi bir hata yakalama olmadan başarısız aşağıdaki kod var eşleşti değil başarısız: GetRowCount() bir Long dönmez zamanMapTo Ya sessiz o

(actor ? GetRowCount()).mapTo[Either[Rejection, Long]] map { 
     case Left(x) => ctx.reject(x) 
     case Right(totalRows) => ctx.complete(totalRows) 
} 

ama mesela bir String, hiçbir hata yakalandı ve Sadece sessizce başarısız.

(actor ? GetRowCount()).mapTo[Either[Rejection, Any]] map { 
     case Left(x) => ctx.reject(x) 
     case Right(totalRows: Long) => ctx.complete(totalRows) 
     case _ => ctx.reject(Rejection("Type mismatch")) 
} 

Ama daha iyi bir yanıt vardır:

aşağıdaki kullanmayı düşünüyorum?

cevap

0

ben kullanırım recover veya recoverWith

(actor ? GetRowCount).mapTo[Either[Rejection, Long]] map { 
    case Left(x) => ctx.reject(x) 
    case Right(totalRows) => ctx.complete(totalRows) 
} recover { 
    case e: Throwable => 
    logger.error(e, "Some thing wrong while performing ask") 
    //throw an error or return something here 
}