Example #1
0
        public bool?CheckStatusCode(IRestResponse response, string notFoundMsg = null, string badRequestMsg = null, string unauthorizedMsg = null, string internalServerErrorMsg = null, string genericMgs = null)
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                ErrorWriter.CustomError($"RES CONTENT : {response.Content} \nSTATUS ID : {response.StatusCode}");
            }


            switch (response.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                throw new Exception(badRequestMsg ?? Resources.Messages.APIError_BadRequest);

            case HttpStatusCode.Unauthorized:
                throw new Exception(unauthorizedMsg ?? Resources.Messages.APIError_Unauthorized);

            case HttpStatusCode.InternalServerError:
                throw new Exception(internalServerErrorMsg ?? Resources.Messages.APIError_InternalServerError);

            case HttpStatusCode.NotFound:
                throw new Exception(notFoundMsg ?? Resources.Messages.APIError_NotFound);

            case HttpStatusCode.OK:
                return(true);

            default:
                throw new Exception(genericMgs ?? Resources.Messages.Error_SolicitudFallida);
            }
        }