/// <summary> /// Throws DreamFactoryException on bad HTTP status code. /// </summary> /// <param name="response"><see cref="IHttpResponse"/> instance.</param> /// <param name="serializer">Serializer instance.</param> public static void ThrowOnBadStatus(IHttpResponse response, IContentSerializer serializer) { if (response == null) { throw new ArgumentNullException("response"); } if (serializer == null) { throw new ArgumentNullException("serializer"); } if (response.Code >= 200 && response.Code < 300) { return; } string message; switch (response.Code) { case 400: message = "400: Bad Request - Request does not have a valid format, all required parameters, etc."; break; case 401: message = "401 - The login information did not match any records on the backend."; break; case 403: message = "403 - CORS has not been enabled and you’re trying to use the API cross-domain."; break; case 404: message = "404 - The requested DSP is not found."; break; case 500: message = "500 - Internal server error"; break; default: message = string.Format("Got HTTP error: {0}", response.Code); break; } message = TryGetErrorMessage(response, serializer, message); DreamFactoryException exception = new DreamFactoryException(message); exception.Data.Add("Method", response.Request.Method); exception.Data.Add("URL", response.Request.Url); throw exception; }