Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
AURA
tank
Commits
d59384c2
Commit
d59384c2
authored
5 years ago
by
Christian Pointner
Browse files
Options
Downloads
Plain Diff
Merge branch 'topic/create-file-error'
parents
6b7fd168
6348d39b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/v1/files.go
+27
-18
27 additions, 18 deletions
api/v1/files.go
api/v1/types.go
+3
-2
3 additions, 2 deletions
api/v1/types.go
api/v1/utils.go
+6
-2
6 additions, 2 deletions
api/v1/utils.go
with
36 additions
and
22 deletions
api/v1/files.go
+
27
−
18
View file @
d59384c2
...
...
@@ -90,17 +90,14 @@ func (api *API) CreateFileForShow(c *gin.Context) {
}
// From here on, in case of an error we should either delete the newly created
// file or at least return the id of it so the API user can deal with the problem.
status
:=
http
.
StatusCreated
// file or return the file object as ErrorResponse.Detail so the API user can deal with the problem.
refID
:=
""
// TODO: get this from query paremeter
job
,
err
:=
api
.
importer
.
CreateJob
(
showID
,
file
.
ID
,
srcURI
,
sess
.
Username
,
refID
)
if
err
!=
nil
{
status
,
_
=
statusCodeFromError
(
err
)
goto
create_file_response
}
if
err
=
job
.
Start
(
context
.
Background
(),
3
*
time
.
Hour
);
err
!=
nil
{
// TODO: hardcoded value
status
,
_
=
statusCodeFromError
(
err
)
goto
create_file_response
}
...
...
@@ -112,20 +109,32 @@ func (api *API) CreateFileForShow(c *gin.Context) {
}
create_file_response
:
if
file
,
err
=
api
.
store
.
GetFile
(
showID
,
file
.
ID
);
err
!=
nil
{
// GetFile only fails if the file does not exist or there is
// a problem with the database connection. The former probably
// means that the file got deleted by somebody else... all other
// errors most likely mean that the file still exists. In this
// case it's better to return the file so the API user can use
// the file ID for further inspection.
if
err
==
store
.
ErrNotFound
{
sendError
(
c
,
err
)
return
}
status
,
_
=
statusCodeFromError
(
err
)
}
c
.
JSON
(
status
,
file
)
// GetFile only fails if the file does not exist or there is
// a problem with the database connection. The former probably
// means that the file got deleted by somebody else... all other
// errors most likely mean that the file still exists. In this
// case it's better to return the file so the API user can use
// the file ID for further inspection.
getFile
,
getErr
:=
api
.
store
.
GetFile
(
showID
,
file
.
ID
)
if
getErr
==
store
.
ErrNotFound
{
sendError
(
c
,
ErrFileVanished
)
return
}
// don't mask the original error
if
err
==
nil
{
err
=
getErr
}
if
getFile
!=
nil
{
file
=
getFile
}
if
err
==
nil
{
c
.
JSON
(
http
.
StatusCreated
,
file
)
return
}
status
,
errResp
:=
statusCodeFromError
(
err
)
errResp
.
Detail
=
file
c
.
JSON
(
status
,
errResp
)
}
func
(
api
*
API
)
ReadFileOfShow
(
c
*
gin
.
Context
)
{
...
...
This diff is collapsed.
Click to expand it.
api/v1/types.go
+
3
−
2
View file @
d59384c2
...
...
@@ -35,11 +35,12 @@ import (
var
(
ErrNotFlowJSUpload
=
errors
.
New
(
"this is not a flow.js upload"
)
ErrFlowJSChunkAlreadUploading
=
errors
.
New
(
"chunk is already uploading or done"
)
ErrFileVanished
=
errors
.
New
(
"the file vanished from the store while preparing the import"
)
)
type
ErrorResponse
struct
{
Error
string
`json:"error,omitempty"`
Detail
s
interface
{}
`json:"detail
s
,omitempty"`
Error
string
`json:"error,omitempty"`
Detail
interface
{}
`json:"detail,omitempty"`
}
// Shows
...
...
This diff is collapsed.
Click to expand it.
api/v1/utils.go
+
6
−
2
View file @
d59384c2
...
...
@@ -45,15 +45,19 @@ func statusCodeFromError(err error) (code int, response ErrorResponse) {
switch
err
.
(
type
)
{
case
*
store
.
ErrFileInUse
:
code
=
http
.
StatusConflict
response
.
Detail
s
=
err
response
.
Detail
=
err
case
store
.
ErrInvalidMetadataField
:
code
=
http
.
StatusBadRequest
case
*
importer
.
JobSourceResult
:
response
.
Detail
s
=
err
.
(
*
importer
.
JobSourceResult
)
.
Log
response
.
Detail
=
err
.
(
*
importer
.
JobSourceResult
)
.
Log
default
:
switch
err
{
case
ErrNotFlowJSUpload
:
code
=
http
.
StatusConflict
case
ErrFlowJSChunkAlreadUploading
:
code
=
http
.
StatusConflict
case
ErrFileVanished
:
code
=
http
.
StatusConflict
case
store
.
ErrNotImplemented
:
code
=
http
.
StatusNotImplemented
...
...
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