private bool IsIDValid(int id) { if (!_contactContext.Contacts.Any(c => c.ID == id)) { throw ClientErrors.InvalidId(); } else { return(true); } }
public static void ValidateRequest(Contact contact) { Regex emailRegex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match match = emailRegex.Match(contact.EmailID); if (!match.Success) { throw ClientErrors.InvalidEmailId(); } if (contact.FirstName.Length > 50) { throw ClientErrors.InvalidFirstName(); } if (contact.LastName.Length > 50) { throw ClientErrors.InvalidLastName(); } }
void IObserver <DataChanged <IClient> > .OnError(Exception error) { ClientErrors.Enqueue(error); }
/// <summary> /// Вызов событий об ошибках /// </summary> /// <param name="type">тип ошибки</param> /// <param name="message">сообщение об ошибке</param> internal void CallErrorClient(ClientErrorType type, string message) { Task.Factory.StartNew(() => ClientErrors?.Invoke(this, new ErrorClientArgs(type, message))); }
private void BadRequest(HttpActionContext actionContext) { Trace.TraceError("Trottle Attribute sending error response: 400. Bad request, since the access_token is not found in the request header"); actionContext.Response = ClientErrors.InvalidJson(actionContext); }
private void Forbidden(HttpActionContext actionContext) { Trace.TraceError("Trottle Attribute sending error response: 403. Application Rate Limit Exceeded."); actionContext.Response = ClientErrors.RateLimitExceeded(actionContext); }
private void BadRequest(HttpActionContext actionContext) { Trace.TraceWarning("Basic Authorization Attribute sending error response: 400. Access token not present"); actionContext.Response = ClientErrors.InvalidJson(actionContext); }
private void Forbidden(HttpActionContext actionContext) { Trace.TraceWarning("Basic Authorization Attribute sending error response: 403. No valid session for the token."); actionContext.Response = ClientErrors.InvalidToken(actionContext); }