private static void HandleNotFoundError(ResponseErrorParameters errorParameters) { string requestUrl = errorParameters.Url; string requestBody = errorParameters.RequestBody; string responseBody = errorParameters.ResponseBody; string reasonPhrase = errorParameters.ServerReasonPhrase; RequestObjectType requestObjectType = errorParameters.RequestObjectType; bool isDeviceRequest = errorParameters.IsDeviceRequest; bool isInAuthorizationPolling = errorParameters.IsInAuthorizationPolling; bool isAuthorizationRequest = errorParameters.IsAuthorizationRequest; bool isAuthorizationRevoke = errorParameters.IsAuthorizationRevoke; if (isDeviceRequest || isInAuthorizationPolling) { throw new TraktAuthenticationDeviceException("Not Found - invalid device code") { StatusCode = errorParameters.StatusCode, RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; } else if (isAuthorizationRequest) { throw new TraktAuthenticationOAuthException("Resource not found") { StatusCode = errorParameters.StatusCode, RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; } else if (isAuthorizationRevoke) { throw new TraktAuthenticationException("Resource not found") { StatusCode = errorParameters.StatusCode, RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; } else if (requestObjectType != RequestObjectType.Unspecified && !isDeviceRequest && !isInAuthorizationPolling && !isAuthorizationRequest && !isAuthorizationRevoke) { HandleNotFoundObjectError(errorParameters, requestUrl, requestBody, responseBody, reasonPhrase, requestObjectType); } throw new TraktNotFoundException($"Resource not found - Reason Phrase: {reasonPhrase}") { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; }
/// <summary> /// Функция для добавления обьектов к запросу /// </summary> /// <param name="requestObj">Строка с параметрами например var=1;test=2;</param> /// <param name="type">Тип запроса</param> private void addRequestObject(string requestObj, RequestObjectType type) { foreach (string str in requestObj.Split(';')) { if (str.Contains("=")) { var v = str.Replace(" ", "").Split('='); if (type == RequestObjectType.Cookie) { request.AddCookie(v[0], v[1]); } else if (type == RequestObjectType.Header) { request.AddHeader(v[0], v[1]); } } } }
public override string ToString() { return(RequestObjectType.ToString() + "Id=" + Id); }
private static void HandleNotFoundObjectError(ResponseErrorParameters errorParameters, string requestUrl, string requestBody, string responseBody, string reasonPhrase, RequestObjectType requestObjectType) { string objectId = errorParameters.ObjectId; uint seasonNr = errorParameters.SeasonNumber; uint episodeNr = errorParameters.EpisodeNumber; switch (requestObjectType) { case RequestObjectType.Episodes: throw new TraktEpisodeNotFoundException(objectId, seasonNr, episodeNr) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; case RequestObjectType.Seasons: throw new TraktSeasonNotFoundException(objectId, seasonNr) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; case RequestObjectType.Shows: throw new TraktShowNotFoundException(objectId) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; case RequestObjectType.Movies: throw new TraktMovieNotFoundException(objectId) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; case RequestObjectType.People: throw new TraktPersonNotFoundException(objectId) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; case RequestObjectType.Comments: throw new TraktCommentNotFoundException(objectId) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; case RequestObjectType.Lists: throw new TraktListNotFoundException(objectId) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; case RequestObjectType.Object: throw new TraktObjectNotFoundException(objectId) { RequestUrl = requestUrl, RequestBody = requestBody, Response = responseBody, ServerReasonPhrase = reasonPhrase }; } }