第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

在ASP.NET Web API中返回錯(cuò)誤的最佳實(shí)踐

在ASP.NET Web API中返回錯(cuò)誤的最佳實(shí)踐

C#
一只萌萌小番薯 2019-10-12 14:39:03
我對我們向客戶返回錯(cuò)誤的方式感到擔(dān)憂。當(dāng)我們收到錯(cuò)誤消息時(shí),是否通過拋出HttpResponseException立即返回錯(cuò)誤消息:public void Post(Customer customer){    if (string.IsNullOrEmpty(customer.Name))    {        throw new HttpResponseException("Customer Name cannot be empty", HttpStatusCode.BadRequest)     }    if (customer.Accounts.Count == 0)    {         throw new HttpResponseException("Customer does not have any account", HttpStatusCode.BadRequest)     }}否則我們會累積所有錯(cuò)誤,然后發(fā)回給客戶:public void Post(Customer customer){    List<string> errors = new List<string>();    if (string.IsNullOrEmpty(customer.Name))    {        errors.Add("Customer Name cannot be empty");     }    if (customer.Accounts.Count == 0)    {         errors.Add("Customer does not have any account");     }    var responseMessage = new HttpResponseMessage<List<string>>(errors, HttpStatusCode.BadRequest);    throw new HttpResponseException(responseMessage);}這只是一個(gè)示例代碼,與驗(yàn)證錯(cuò)誤或服務(wù)器錯(cuò)誤無關(guān),我只想了解最佳實(shí)踐,每種方法的優(yōu)缺點(diǎn)。
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 771 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號