|
1 | 1 | using Newtonsoft.Json;
|
| 2 | + |
2 | 3 | using System;
|
3 | 4 | using System.Collections.Generic;
|
4 | 5 | using System.Diagnostics;
|
@@ -154,33 +155,18 @@ private async Task<HttpResponseMessage> HttpRequestRaw(string url = null, HttpMe
|
154 | 155 | {
|
155 | 156 | throw new HttpRequestException("OpenAI had an internal server error, which can happen occasionally. Please retry your request. " + GetErrorMessage(resultAsString, response, Endpoint, url));
|
156 | 157 | }
|
| 158 | + else if (resultAsString.IndexOf("504 Gateway Time-out") !=-1) |
| 159 | + { |
| 160 | + //resultAsString == "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty/1.21.4.2</center>\r\n</body>\r\n</html>\r\n |
| 161 | + throw new HttpRequestException("OpenAI had a 504 Gateway Time-out, which can happen occasionally. Please retry your request. " + GetErrorMessage(resultAsString, response, Endpoint, url)); |
| 162 | + } |
157 | 163 | else
|
158 | 164 | {
|
159 | 165 | var errorToThrow = new HttpRequestException(GetErrorMessage(resultAsString, response, Endpoint, url));
|
160 | 166 | ApiErrorResponse? parsedError;
|
161 |
| - try |
162 |
| - { |
163 |
| - parsedError = JsonConvert.DeserializeObject<ApiErrorResponse>(resultAsString); |
164 |
| - } |
165 |
| - catch (Exception ex) |
166 |
| - { |
167 |
| - //typically gateway timeout 504 |
168 |
| - //"<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty/1.21.4.2</center>\r\n</body>\r\n</html>\r\n" |
169 |
| - if (resultAsString == "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty/1.21.4.2</center>\r\n</body>\r\n</html>\r\n") |
170 |
| - { |
171 |
| - parsedError = new ApiErrorResponse(); |
172 |
| - parsedError.Error = new ApiErrorResponseError(); |
173 |
| - parsedError.Error.Message = "504 Gateway Time-out"; |
174 |
| - parsedError.Error.ErrorType = "Gateway Time-out"; |
175 |
| - parsedError.Error.Parameter = "N/A"; |
176 |
| - parsedError.Error.ErrorCode = "504"; |
177 |
| - } |
178 |
| - else |
179 |
| - { |
180 |
| - var a = 3; |
181 |
| - throw ex; |
182 |
| - } |
183 |
| - } |
| 167 | + |
| 168 | + parsedError = JsonConvert.DeserializeObject<ApiErrorResponse>(resultAsString); |
| 169 | + |
184 | 170 | try
|
185 | 171 | {
|
186 | 172 | errorToThrow.Data.Add("message", parsedError.Error.Message);
|
|
0 commit comments