angular - Display web api exception in angular2 -


i working on project web api backend , angular2 front end. having issue showing server error in angular2. every time server error throws cors error.

here sample api  public iactionresult post([frombody] visitor model) {   if (model == null) throw new httpresponseexception(new httpresponsemessage(httpstatuscode.nocontent)   {       reasonphrase = "missing model in post"   });   _registerservice.register(model);   return ok(model);     }   , here angular2 service   addvisit(visit: visit) {  let siteid = visit.siteid; let body = json.stringify(visit); let headers = new headers({ 'content-type': 'application/json' }); let options = new requestoptions({ headers: headers });  return this.authhttp     .post(`${this._visitorsurl}` + siteid, body, options)     .map(res => {         res.json();         console.log("map: " + json.stringify(res.json()));     })     .catch(err => console.log(err)); 

}

when model null return error 502 or cors error when model not null retrn 200

my problem how can display error server return.

couldn't add

error =>  this.errormessage = <any>error; 

on if check null? use inside .subscribe .map believe looking for?


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -