我得到執行異常如何捕捉scala playframework中的執行異常?
[APIError: You must provide an email address in order to create a ticket.]
有可能趕上這個錯誤,並張貼只有
"You must provide an email address in order to create a ticket."
這個錯誤應該在視圖頁面showup。
,讓錯誤代碼:
val question = uservoice.post("/api/v1/tickets.json", ticket).getJSONObject("ticket")
控制器:
def contactSave = withOptionUser { user => implicit request =>
contactForm.bindFromRequest.fold(
formWithErrors => BadRequest(html.anon.contact(user, formWithErrors)),
c => {
val uservoice = new com.uservoice.Client(SUBDOMAIN, API_KEY, API_SECRET)
val ticketMsg = Map("state" -> "open","subject" -> c._2, "message" -> c._3).toMap[String,Object].asJava
val ticket = Map("email" -> c._1, "ticket" -> ticketMsg).toMap[String,Object].asJava
Logger.debug(ticket.toString)
val question = uservoice.post("/api/v1/tickets.json", ticket).getJSONObject("ticket")
Logger.debug(question.toString)
Ok(views.html.anon.contactThanks(user))
}
)
}
HTML:
@main("Contact Us",user,"contact",stylesheet, scripts) {
@helper.form(routes.UservoiceController.contactSave) {
<section class="contact">
<div class="contactBox contentBox">
<div class="leftColumn">
<h1>Contact Us</h1>
<span>You can fill out this form for any general inquiries, comments, etc.</span>
<span>You can also find us on Facebook and Twitter!</span>
<div class="social">
@form.globalError.map { error =>
<span class="error" data-xpl="loginError">
@error.message
</span>
在發佈到該API之前,您不應該檢查有效的電子郵件地址嗎?盲目捕捉所有異常情況可能會掩蓋其他錯誤。 –
嗨肢體,代碼是使用第三方電子郵件發送,我無法找到他們如何驗證他們的電子郵件..所以我想在找出使用的驗證時趕上錯誤。 – Monnster