we can use HttpResponseException to return an HttpError:
public Employee GetEmployee(int empid) { Employee emp= repository.Get(empid); if (emp== null) { var message = string.Format("Employee with id = {0} not found", empid); throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); } else { return emp; } }
public Employee GetEmployee(int empid) { Employee emp= repository.Get(empid); if (emp== null) { var message = string.Format("Employee with id = {0} not found", empid); throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); } else { return emp; } }
No comments:
Post a Comment