/// <summary> /// Select a controller. The <paramref name="request"/> parameter is guaranteed not to be <c>null</c>. /// </summary> /// <param name="request"></param> /// <returns></returns> protected virtual HttpControllerDescriptor OnSelectController(HttpRequestMessage request) { ControllerIdentification controllerName = this.GetControllerIdentificationFromRequest(request); if (String.IsNullOrEmpty(controllerName.Name)) { throw new HttpResponseException(request.CreateResponse(HttpStatusCode.NotFound)); } HttpControllerDescriptor controllerDescriptor; if (this._controllerInfoCache.Value.TryGetValue(controllerName, out controllerDescriptor)) { return(controllerDescriptor); } ICollection <Type> matchingTypes = this._controllerTypeCache.GetControllerTypes(controllerName); // ControllerInfoCache is already initialized. Contract.Assert(matchingTypes.Count != 1); if (matchingTypes.Count == 0) { // no matching types throw ApiControllerNotFoundException.Create(controllerName); } // multiple matching types throw AmbigiousApiRequestException.Create(controllerName, request.GetRouteData().Route, matchingTypes); }
private static HttpResponseMessage HandleExceptionInternal(ExceptionContext context, AmbigiousApiRequestException exception) { if (exception == null) { return null; } // multiple matching types return context.Request.CreateResponse(HttpStatusCode.InternalServerError, exception.Message); }