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
18705152
Commit
18705152
authored
5 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
return file object even if there is a problem with the import
parent
5be80859
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/v1/files.go
+23
-27
23 additions, 27 deletions
api/v1/files.go
api/v1/utils.go
+9
-3
9 additions, 3 deletions
api/v1/utils.go
with
32 additions
and
30 deletions
api/v1/files.go
+
23
−
27
View file @
18705152
...
...
@@ -88,32 +88,20 @@ func (api *API) CreateFileForShow(c *gin.Context) {
sendError
(
c
,
err
)
return
}
// TODO: from here on, in case of an error we should either delete the newly created
// file or at least return the id of the created file so the UI can deal with it.
// 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
refID
:=
""
// TODO: get this from query paremeter
job
,
err
:=
api
.
importer
.
CreateJob
(
showID
,
file
.
ID
,
srcURI
,
sess
.
Username
,
refID
)
if
err
!=
nil
{
// possible errors:
// - any error returned by store.GetFile():
// possible reasons for this:
// * connection problem to the store database
// * somebody deleted the file
// - importer.ErrFileNotNew -> leave file
sendError
(
c
,
err
)
return
status
,
_
=
statusCodeFromError
(
err
)
goto
create_file_response
}
if
err
=
job
.
Start
(
context
.
Background
(),
3
*
time
.
Hour
);
err
!=
nil
{
// TODO: hardcoded value
// possible errors:
// - importer.ErrAlreadyCanceled -> ??
// - error while creating job workdir -> ??
// - importer.ErrTooManyJobs -> ??
sendError
(
c
,
err
)
return
}
if
waitFor
==
""
{
c
.
JSON
(
http
.
StatusCreated
,
file
)
return
status
,
_
=
statusCodeFromError
(
err
)
goto
create_file_response
}
switch
waitFor
{
...
...
@@ -122,14 +110,22 @@ func (api *API) CreateFileForShow(c *gin.Context) {
case
"done"
:
<-
job
.
Done
()
}
create_file_response
:
if
file
,
err
=
api
.
store
.
GetFile
(
showID
,
file
.
ID
);
err
!=
nil
{
// possible reasons why this failed:
// - connection problem to the store database
// - somebody deleted the file
sendError
(
c
,
err
)
return
}
c
.
JSON
(
http
.
StatusCreated
,
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.
if
err
==
store
.
ErrNotFound
{
sendError
(
c
,
err
)
return
}
status
,
_
=
statusCodeFromError
(
err
)
}
c
.
JSON
(
status
,
file
)
}
func
(
api
*
API
)
ReadFileOfShow
(
c
*
gin
.
Context
)
{
...
...
This diff is collapsed.
Click to expand it.
api/v1/utils.go
+
9
−
3
View file @
18705152
...
...
@@ -38,9 +38,10 @@ func idFromString(s string) (uint64, error) {
return
strconv
.
ParseUint
(
s
,
10
,
64
)
}
func
sendError
(
c
*
gin
.
Context
,
err
error
)
{
code
:=
http
.
StatusInternalServerError
response
:=
ErrorResponse
{
Error
:
err
.
Error
()}
func
statusCodeFromError
(
err
error
)
(
code
int
,
response
ErrorResponse
)
{
code
=
http
.
StatusInternalServerError
response
=
ErrorResponse
{
Error
:
err
.
Error
()}
switch
err
.
(
type
)
{
case
*
store
.
ErrFileInUse
:
code
=
http
.
StatusConflict
...
...
@@ -83,6 +84,11 @@ func sendError(c *gin.Context, err error) {
code
=
http
.
StatusConflict
}
}
return
}
func
sendError
(
c
*
gin
.
Context
,
err
error
)
{
code
,
response
:=
statusCodeFromError
(
err
)
c
.
JSON
(
code
,
response
)
}
...
...
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