Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Zwordi
funkwhale
Commits
6f79dd47
Verified
Commit
6f79dd47
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Now return proper error payload on subsonic API
parent
f5225d32
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/funkwhale_api/subsonic/renderers.py
+6
-0
6 additions, 0 deletions
api/funkwhale_api/subsonic/renderers.py
api/funkwhale_api/subsonic/views.py
+23
-16
23 additions, 16 deletions
api/funkwhale_api/subsonic/views.py
with
29 additions
and
16 deletions
api/funkwhale_api/subsonic/renderers.py
+
6
−
0
View file @
6f79dd47
...
...
@@ -15,6 +15,9 @@ class SubsonicJSONRenderer(renderers.JSONRenderer):
}
}
final
[
'
subsonic-response
'
].
update
(
data
)
if
'
error
'
in
final
:
# an error was returned
final
[
'
subsonic-response
'
][
'
status
'
]
=
'
failed
'
return
super
().
render
(
final
,
accepted_media_type
,
renderer_context
)
...
...
@@ -31,6 +34,9 @@ class SubsonicXMLRenderer(renderers.JSONRenderer):
'
version
'
:
'
1.16.0
'
,
}
final
.
update
(
data
)
if
'
error
'
in
final
:
# an error was returned
final
[
'
status
'
]
=
'
failed
'
tree
=
dict_to_xml_tree
(
'
subsonic-response
'
,
final
)
return
b
'
<?xml version=
"
1.0
"
encoding=
"
UTF-8
"
?>
\n
'
+
ET
.
tostring
(
tree
,
encoding
=
'
utf-8
'
)
...
...
This diff is collapsed.
Click to expand it.
api/funkwhale_api/subsonic/views.py
+
23
−
16
View file @
6f79dd47
...
...
@@ -31,15 +31,19 @@ def find_object(queryset, model_field='pk', field='id', cast=int):
raw_value
=
data
[
field
]
except
KeyError
:
return
response
.
Response
({
'
code
'
:
10
,
'
message
'
:
"
required parameter
'
{}
'
not present
"
.
format
(
field
)
'
error
'
:
{
'
code
'
:
10
,
'
message
'
:
"
required parameter
'
{}
'
not present
"
.
format
(
field
)
}
})
try
:
value
=
cast
(
raw_value
)
except
(
TypeError
,
ValidationError
):
return
response
.
Response
({
'
code
'
:
0
,
'
message
'
:
'
For input string
"
{}
"'
.
format
(
raw_value
)
'
error
'
:
{
'
code
'
:
0
,
'
message
'
:
'
For input string
"
{}
"'
.
format
(
raw_value
)
}
})
qs
=
queryset
if
hasattr
(
qs
,
'
__call__
'
):
...
...
@@ -48,9 +52,11 @@ def find_object(queryset, model_field='pk', field='id', cast=int):
obj
=
qs
.
get
(
**
{
model_field
:
value
})
except
qs
.
model
.
DoesNotExist
:
return
response
.
Response
({
'
code
'
:
70
,
'
message
'
:
'
{} not found
'
.
format
(
qs
.
model
.
__class__
.
__name__
)
'
error
'
:
{
'
code
'
:
70
,
'
message
'
:
'
{} not found
'
.
format
(
qs
.
model
.
__class__
.
__name__
)
}
})
kwargs
[
'
obj
'
]
=
obj
return
func
(
self
,
request
,
*
args
,
**
kwargs
)
...
...
@@ -83,15 +89,14 @@ class SubsonicViewSet(viewsets.GenericViewSet):
payload
=
{
'
status
'
:
'
failed
'
}
try
:
if
exc
.
__class__
in
mapping
:
code
,
message
=
mapping
[
exc
.
__class__
]
except
KeyError
:
return
super
().
handle_exception
(
exc
)
else
:
payload
[
'
error
'
]
=
{
'
code
'
:
code
,
'
message
'
:
message
}
return
super
().
handle_exception
(
exc
)
payload
[
'
error
'
]
=
{
'
code
'
:
code
,
'
message
'
:
message
}
return
response
.
Response
(
payload
,
status
=
200
)
...
...
@@ -450,8 +455,10 @@ class SubsonicViewSet(viewsets.GenericViewSet):
name
=
data
.
get
(
'
name
'
,
''
)
if
not
name
:
return
response
.
Response
({
'
code
'
:
10
,
'
message
'
:
'
Playlist ID or name must be specified.
'
'
error
'
:
{
'
code
'
:
10
,
'
message
'
:
'
Playlist ID or name must be specified.
'
}
},
data
)
playlist
=
request
.
user
.
playlists
.
create
(
...
...
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