@@ -12,6 +12,49 @@ var ChatGPTModels = [
1212
1313var SYSTEM_PROMPT = "You are a translation engine that can only translate text and cannot interpret it."
1414
15+ var HttpErrorCodes = {
16+ "400" : "Bad Request" ,
17+ "401" : "Unauthorized" ,
18+ "402" : "Payment Required" ,
19+ "403" : "Forbidden" ,
20+ "404" : "Not Found" ,
21+ "405" : "Method Not Allowed" ,
22+ "406" : "Not Acceptable" ,
23+ "407" : "Proxy Authentication Required" ,
24+ "408" : "Request Timeout" ,
25+ "409" : "Conflict" ,
26+ "410" : "Gone" ,
27+ "411" : "Length Required" ,
28+ "412" : "Precondition Failed" ,
29+ "413" : "Payload Too Large" ,
30+ "414" : "URI Too Long" ,
31+ "415" : "Unsupported Media Type" ,
32+ "416" : "Range Not Satisfiable" ,
33+ "417" : "Expectation Failed" ,
34+ "418" : "I'm a teapot" ,
35+ "421" : "Misdirected Request" ,
36+ "422" : "Unprocessable Entity" ,
37+ "423" : "Locked" ,
38+ "424" : "Failed Dependency" ,
39+ "425" : "Too Early" ,
40+ "426" : "Upgrade Required" ,
41+ "428" : "Precondition Required" ,
42+ "429" : "Too Many Requests" ,
43+ "431" : "Request Header Fields Too Large" ,
44+ "451" : "Unavailable For Legal Reasons" ,
45+ "500" : "Internal Server Error" ,
46+ "501" : "Not Implemented" ,
47+ "502" : "Bad Gateway" ,
48+ "503" : "Service Unavailable" ,
49+ "504" : "Gateway Timeout" ,
50+ "505" : "HTTP Version Not Supported" ,
51+ "506" : "Variant Also Negotiates" ,
52+ "507" : "Insufficient Storage" ,
53+ "508" : "Loop Detected" ,
54+ "510" : "Not Extended" ,
55+ "511" : "Network Authentication Required"
56+ }
57+
1558/**
1659 * @param {string } url
1760 * @returns {string }
@@ -158,7 +201,6 @@ function buildRequestBody(model, isChatGPTModel, query) {
158201 } ;
159202}
160203
161-
162204/**
163205 * @param {Bob.TranslateQuery } query
164206 * @param {Bob.HttpResponse } result
@@ -170,13 +212,12 @@ function handleError(query, result) {
170212 query . onCompletion ( {
171213 error : {
172214 type : reason ,
173- message : `接口响应错误 - ${ result . data . error . message } ` ,
174- addtion : `${ statusCode } : ${ JSON . stringify ( result ) } ` ,
215+ message : `接口响应错误 - ${ HttpErrorCodes [ statusCode ] } ` ,
216+ addtion : `${ JSON . stringify ( result ) } ` ,
175217 } ,
176218 } ) ;
177219}
178220
179-
180221/**
181222 * @param {Bob.TranslateQuery } query
182223 * @param {boolean } isChatGPTModel
0 commit comments