Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
498f9e2f
Commit
498f9e2f
authored
Apr 13, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop Fail500 and LogError from panicing with nil request or error
parent
41633621
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
internal/helper/helpers.go
internal/helper/helpers.go
+8
-2
internal/helper/helpers_test.go
internal/helper/helpers_test.go
+11
-0
No files found.
internal/helper/helpers.go
View file @
498f9e2f
...
...
@@ -19,12 +19,18 @@ const NginxResponseBufferHeader = "X-Accel-Buffering"
func
Fail500
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
error
)
{
http
.
Error
(
w
,
"Internal server error"
,
500
)
if
err
!=
nil
{
captureRavenError
(
r
,
err
)
}
printError
(
r
,
err
)
}
func
LogError
(
r
*
http
.
Request
,
err
error
)
{
if
err
!=
nil
{
captureRavenError
(
r
,
err
)
}
printError
(
r
,
err
)
}
...
...
internal/helper/helpers_test.go
View file @
498f9e2f
...
...
@@ -99,3 +99,14 @@ func TestApplicationJson(t *testing.T) {
req
.
Header
.
Set
(
"Content-Type"
,
"text/plain"
)
assert
.
False
(
t
,
IsApplicationJson
(
req
),
"expected not to match 'text/plain' as 'application/json'"
)
}
func
TestFail500WorksWithNils
(
t
*
testing
.
T
)
{
body
:=
bytes
.
NewBuffer
(
nil
)
w
:=
httptest
.
NewRecorder
()
w
.
Body
=
body
Fail500
(
w
,
nil
,
nil
)
assert
.
Equal
(
t
,
http
.
StatusInternalServerError
,
w
.
Code
)
assert
.
Equal
(
t
,
"Internal server error
\n
"
,
body
.
String
())
}
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