Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
imghost
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Janne Mareike Koschinski
imghost
Commits
7b3eb892
Verified
Commit
7b3eb892
authored
5 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Improve error reporting
parent
291db9db
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
page_image_detail.go
+19
-9
19 additions, 9 deletions
page_image_detail.go
util.go
+9
-0
9 additions, 0 deletions
util.go
with
28 additions
and
9 deletions
page_image_detail.go
+
19
−
9
View file @
7b3eb892
...
...
@@ -17,8 +17,8 @@ type ImageDetailData struct {
func
pageImageDetail
(
ctx
PageContext
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
user
:=
parseUser
(
r
)
_
,
imageId
:=
path
.
Split
(
r
.
URL
.
Path
)
result
,
err
:=
ctx
.
Database
.
Query
(
`
SELECT
id,
...
...
@@ -32,15 +32,20 @@ func pageImageDetail(ctx PageContext) http.Handler {
WHERE id = $1
`
,
imageId
)
if
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"An error occured: %s"
,
err
.
Error
())
_
=
returnError
(
w
,
http
.
StatusInternalServerError
,
"Internal Server Error"
)
return
}
var
info
Image
if
result
.
Next
()
{
var
owner
string
err
:=
result
.
Scan
(
&
info
.
Id
,
&
owner
,
&
info
.
Title
,
&
info
.
Description
,
&
info
.
CreatedAt
,
&
info
.
OriginalName
,
&
info
.
MimeType
)
if
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"An error occured: %s"
,
err
.
Error
())
_
=
returnError
(
w
,
http
.
StatusInternalServerError
,
"Internal Server Error"
)
return
}
switch
r
.
PostFormValue
(
"action"
)
{
...
...
@@ -53,10 +58,12 @@ func pageImageDetail(ctx PageContext) http.Handler {
user
.
Id
,
)
if
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"An error occured: %s"
,
err
.
Error
())
_
=
returnError
(
w
,
http
.
StatusInternalServerError
,
"Internal Server Error"
)
return
}
if
r
.
PostFormValue
(
"from_js"
)
==
"true"
{
returnJson
(
w
,
true
)
_
=
returnJson
(
w
,
true
)
}
else
{
http
.
Redirect
(
w
,
r
,
r
.
URL
.
Path
,
http
.
StatusFound
)
}
...
...
@@ -64,12 +71,16 @@ func pageImageDetail(ctx PageContext) http.Handler {
case
"delete"
:
_
,
err
=
ctx
.
Database
.
Exec
(
"DELETE FROM images WHERE id = $1 AND owner = $2"
,
info
.
Id
,
user
.
Id
)
if
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"An error occured: %s"
,
err
.
Error
())
_
=
returnError
(
w
,
http
.
StatusInternalServerError
,
"Internal Server Error"
)
return
}
for
_
,
definition
:=
range
ctx
.
Config
.
Sizes
{
err
:=
os
.
Remove
(
path
.
Join
(
ctx
.
Config
.
TargetFolder
,
fmt
.
Sprintf
(
"%s%s"
,
info
.
Id
,
definition
.
Suffix
)))
if
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
panic
(
err
)
fmt
.
Printf
(
"An error occured: %s"
,
err
.
Error
())
_
=
returnError
(
w
,
http
.
StatusInternalServerError
,
"Internal Server Error"
)
return
}
}
http
.
Redirect
(
w
,
r
,
"/me/images"
,
http
.
StatusFound
)
...
...
@@ -86,7 +97,6 @@ func pageImageDetail(ctx PageContext) http.Handler {
return
}
w
.
WriteHeader
(
http
.
StatusNotFound
)
fmt
.
Fprint
(
w
,
"Image not found"
)
_
=
returnError
(
w
,
http
.
StatusNotFound
,
"Image Not Found"
)
})
}
This diff is collapsed.
Click to expand it.
util.go
+
9
−
0
View file @
7b3eb892
...
...
@@ -73,6 +73,15 @@ func returnJson(w http.ResponseWriter, data interface{}) error {
return
nil
}
func
returnError
(
w
http
.
ResponseWriter
,
code
int
,
message
string
)
error
{
w
.
WriteHeader
(
code
)
if
_
,
err
:=
w
.
Write
([]
byte
(
message
));
err
!=
nil
{
return
err
}
return
nil
}
func
formatTemplate
(
w
http
.
ResponseWriter
,
templateName
string
,
data
interface
{})
error
{
pageTemplate
,
err
:=
template
.
ParseFiles
(
"templates/_base.html"
,
...
...
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