Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
423ceae5
authored
Aug 06, 2025
by
Xyfacai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: error code 显示问题
parent
2e41362f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletions
+10
-1
types/error.go
+10
-1
No files found.
types/error.go
View file @
423ceae5
...
...
@@ -189,9 +189,13 @@ func NewError(err error, errorCode ErrorCode, ops ...NewAPIErrorOptions) *NewAPI
}
func
NewOpenAIError
(
err
error
,
errorCode
ErrorCode
,
statusCode
int
,
ops
...
NewAPIErrorOptions
)
*
NewAPIError
{
if
errorCode
==
ErrorCodeDoRequestFailed
{
err
=
errors
.
New
(
"upstream error: do request failed"
)
}
openaiError
:=
OpenAIError
{
Message
:
err
.
Error
(),
Type
:
string
(
errorCode
),
Code
:
errorCode
,
}
return
WithOpenAIError
(
openaiError
,
statusCode
,
ops
...
)
}
...
...
@@ -199,6 +203,7 @@ func NewOpenAIError(err error, errorCode ErrorCode, statusCode int, ops ...NewAP
func
InitOpenAIError
(
errorCode
ErrorCode
,
statusCode
int
,
ops
...
NewAPIErrorOptions
)
*
NewAPIError
{
openaiError
:=
OpenAIError
{
Type
:
string
(
errorCode
),
Code
:
errorCode
,
}
return
WithOpenAIError
(
openaiError
,
statusCode
,
ops
...
)
}
...
...
@@ -224,7 +229,11 @@ func NewErrorWithStatusCode(err error, errorCode ErrorCode, statusCode int, ops
func
WithOpenAIError
(
openAIError
OpenAIError
,
statusCode
int
,
ops
...
NewAPIErrorOptions
)
*
NewAPIError
{
code
,
ok
:=
openAIError
.
Code
.
(
string
)
if
!
ok
{
code
=
fmt
.
Sprintf
(
"%v"
,
openAIError
.
Code
)
if
openAIError
.
Code
==
nil
{
code
=
fmt
.
Sprintf
(
"%v"
,
openAIError
.
Code
)
}
else
{
code
=
"unknown_error"
}
}
if
openAIError
.
Type
==
""
{
openAIError
.
Type
=
"upstream_error"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment