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
70ec0682
authored
Jan 07, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: recover panic
parent
c92f3272
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
main.go
+9
-1
middleware/recover.go
+2
-2
No files found.
main.go
View file @
70ec0682
...
@@ -104,7 +104,15 @@ func main() {
...
@@ -104,7 +104,15 @@ func main() {
// Initialize HTTP server
// Initialize HTTP server
server
:=
gin
.
New
()
server
:=
gin
.
New
()
server
.
Use
(
gin
.
Recovery
())
server
.
Use
(
gin
.
CustomRecovery
(
func
(
c
*
gin
.
Context
,
err
any
)
{
common
.
SysError
(
fmt
.
Sprintf
(
"panic detected: %v"
,
err
))
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
gin
.
H
{
"message"
:
fmt
.
Sprintf
(
"Panic detected, error: %v. Please submit a issue here: https://github.com/Calcium-Ion/new-api"
,
err
),
"type"
:
"new_api_panic"
,
},
})
}))
// This will cause SSE not to work!!!
// This will cause SSE not to work!!!
//server.Use(gzip.Gzip(gzip.DefaultCompression))
//server.Use(gzip.Gzip(gzip.DefaultCompression))
server
.
Use
(
middleware
.
RequestId
())
server
.
Use
(
middleware
.
RequestId
())
...
...
middleware/recover.go
View file @
70ec0682
...
@@ -16,8 +16,8 @@ func RelayPanicRecover() gin.HandlerFunc {
...
@@ -16,8 +16,8 @@ func RelayPanicRecover() gin.HandlerFunc {
common
.
SysError
(
fmt
.
Sprintf
(
"stacktrace from panic: %s"
,
string
(
debug
.
Stack
())))
common
.
SysError
(
fmt
.
Sprintf
(
"stacktrace from panic: %s"
,
string
(
debug
.
Stack
())))
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
gin
.
H
{
"error"
:
gin
.
H
{
"message"
:
fmt
.
Sprintf
(
"Panic detected, error: %v. Please submit a issue here: https://github.com/
songquanpeng/one
-api"
,
err
),
"message"
:
fmt
.
Sprintf
(
"Panic detected, error: %v. Please submit a issue here: https://github.com/
Calcium-Ion/new
-api"
,
err
),
"type"
:
"
one
_api_panic"
,
"type"
:
"
new
_api_panic"
,
},
},
})
})
c
.
Abort
()
c
.
Abort
()
...
...
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