public override void OnAuthorization(HttpActionContext context) { var customer = ECommerceContext.CurrentCustomer; if (customer != null) { return; } context.Response = FilterHelper.ErrorResponse("Unauthorized access"); }
public override void OnAuthorization(HttpActionContext context) { if (context.Request.RequestUri.Scheme != Uri.UriSchemeHttps) { context.Response = FilterHelper.ErrorResponse("HTTPS required"); } else { base.OnAuthorization(context); } }
public override void OnActionExecuting(HttpActionContext context) { var queryString = context.Request.GetQueryNameValuePairs(); if (queryString.Any(q => q.Key == ParameterName)) { return; } context.Response = FilterHelper.ErrorResponse($"Request validation error : Missing query parameter {ParameterName}"); }
public override void OnActionExecuting(HttpActionContext context) { if (!context.ModelState.IsValid) { var message = context.ModelState.Values?.FirstOrDefault(v => (v.Errors?.Count ?? 0) > 0)?.Errors?.FirstOrDefault()?.ErrorMessage; if (string.IsNullOrEmpty(message)) { message = "Bad request format"; } context.Response = FilterHelper.ErrorResponse($"Request validation error : {message}"); } }
public override void OnException(HttpActionExecutedContext context) { context.Response = FilterHelper.ErrorResponse(context.Exception.Message); logger?.LogException(loggerSource, context.Exception); }