mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Uploader.GetResponse(): Add flag to enable returning non-2xx responses
This allows handling of HTTP responses with non-2xx status codes in uploader code, e.g. to handle REST API errors.
This commit is contained in:
parent
52e3ec4a87
commit
28180cf86a
1 changed files with 7 additions and 1 deletions
|
@ -350,7 +350,7 @@ protected UploadResult SendRequestFileRange(string url, Stream data, string file
|
|||
}
|
||||
|
||||
protected HttpWebResponse GetResponse(HttpMethod method, string url, Stream data = null, string contentType = null, Dictionary<string, string> args = null,
|
||||
NameValueCollection headers = null, CookieCollection cookies = null)
|
||||
NameValueCollection headers = null, CookieCollection cookies = null, bool allowNon2xxResponses = false)
|
||||
{
|
||||
IsUploading = true;
|
||||
StopUploadRequested = false;
|
||||
|
@ -381,6 +381,12 @@ protected HttpWebResponse GetResponse(HttpMethod method, string url, Stream data
|
|||
|
||||
return (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException we) when (we.Response != null && allowNon2xxResponses)
|
||||
{
|
||||
// if we.Response != null, then the request was successful, but
|
||||
// returned a non-200 status code
|
||||
return we.Response as HttpWebResponse;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!StopUploadRequested)
|
||||
|
|
Loading…
Reference in a new issue