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

Lists in Python -

android - can not access to progress bar in an other activity -

java - Vaadin 7 Pass Data Between Views -