Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
b7331824
Commit
b7331824
authored
1 year ago
by
Valera Shaitorov
Browse files
Options
Downloads
Patches
Plain Diff
Добавлена функция для доп обработки ошибки
parent
53565aec
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/transport/http.go
+35
-0
35 additions, 0 deletions
pkg/transport/http.go
with
35 additions
and
0 deletions
pkg/transport/http.go
0 → 100644
+
35
−
0
View file @
b7331824
package
transport
import
(
"bytes"
"io"
"net/http"
"strings"
jsoniter
"github.com/json-iterator/go"
"github.com/pkg/errors"
)
func
DecodeError
(
r
*
http
.
Response
)
error
{
if
r
.
StatusCode
>=
200
&&
r
.
StatusCode
<
300
{
return
nil
}
var
buf
bytes
.
Buffer
if
_
,
err
:=
io
.
Copy
(
&
buf
,
io
.
LimitReader
(
r
.
Body
,
1024
));
err
!=
nil
{
return
err
}
e
:=
struct
{
Error
error
`json:"error"`
}{}
if
err
:=
jsoniter
.
Unmarshal
(
buf
.
Bytes
(),
e
);
err
!=
nil
{
msg
:=
strings
.
TrimSpace
(
buf
.
String
())
if
msg
==
""
{
msg
=
http
.
StatusText
(
r
.
StatusCode
)
}
return
errors
.
New
(
msg
)
}
return
e
.
Error
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment