Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
43981017
Commit
43981017
authored
Jan 24, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/tidal: parse subStatus in error responses
parent
2e1481f4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
4 deletions
+37
-4
TidalError.hxx
src/input/plugins/TidalError.hxx
+12
-2
TidalErrorParser.cxx
src/input/plugins/TidalErrorParser.cxx
+21
-2
TidalErrorParser.hxx
src/input/plugins/TidalErrorParser.hxx
+4
-0
No files found.
src/input/plugins/TidalError.hxx
View file @
43981017
...
...
@@ -33,15 +33,25 @@ class TidalError : public std::runtime_error {
*/
unsigned
status
;
/**
* The Tidal-specific "subStatus". 0 if none was found in the
* JSON response.
*/
unsigned
sub_status
;
public
:
template
<
typename
W
>
TidalError
(
unsigned
_status
,
W
&&
_what
)
noexcept
TidalError
(
unsigned
_status
,
unsigned
_sub_status
,
W
&&
_what
)
noexcept
:
std
::
runtime_error
(
std
::
forward
<
W
>
(
_what
)),
status
(
_status
)
{}
status
(
_status
)
,
sub_status
(
_sub_status
)
{}
unsigned
GetStatus
()
const
noexcept
{
return
status
;
}
unsigned
GetSubStatus
()
const
noexcept
{
return
sub_status
;
}
};
#endif
src/input/plugins/TidalErrorParser.cxx
View file @
43981017
...
...
@@ -28,7 +28,7 @@ using Wrapper = Yajl::CallbacksWrapper<TidalErrorParser>;
static
constexpr
yajl_callbacks
tidal_error_parser_callbacks
=
{
nullptr
,
nullptr
,
nullpt
r
,
Wrapper
::
Intege
r
,
nullptr
,
nullptr
,
Wrapper
::
String
,
...
...
@@ -62,7 +62,23 @@ TidalErrorParser::OnEnd()
else
snprintf
(
what
,
sizeof
(
what
),
"Status %u from Tidal"
,
status
);
throw
TidalError
(
status
,
what
);
throw
TidalError
(
status
,
sub_status
,
what
);
}
inline
bool
TidalErrorParser
::
Integer
(
long
long
value
)
noexcept
{
switch
(
state
)
{
case
State
:
:
NONE
:
case
State
:
:
USER_MESSAGE
:
break
;
case
State
:
:
SUB_STATUS
:
sub_status
=
value
;
break
;
}
return
true
;
}
inline
bool
...
...
@@ -70,6 +86,7 @@ TidalErrorParser::String(StringView value) noexcept
{
switch
(
state
)
{
case
State
:
:
NONE
:
case
State
:
:
SUB_STATUS
:
break
;
case
State
:
:
USER_MESSAGE
:
...
...
@@ -85,6 +102,8 @@ TidalErrorParser::MapKey(StringView value) noexcept
{
if
(
value
.
Equals
(
"userMessage"
))
state
=
State
::
USER_MESSAGE
;
else
if
(
value
.
Equals
(
"subStatus"
))
state
=
State
::
SUB_STATUS
;
else
state
=
State
::
NONE
;
...
...
src/input/plugins/TidalErrorParser.hxx
View file @
43981017
...
...
@@ -39,8 +39,11 @@ class TidalErrorParser final : public YajlResponseParser {
enum
class
State
{
NONE
,
USER_MESSAGE
,
SUB_STATUS
,
}
state
=
State
::
NONE
;
unsigned
sub_status
=
0
;
std
::
string
message
;
public
:
...
...
@@ -57,6 +60,7 @@ protected:
public
:
/* yajl callbacks */
bool
Integer
(
long
long
value
)
noexcept
;
bool
String
(
StringView
value
)
noexcept
;
bool
MapKey
(
StringView
value
)
noexcept
;
bool
EndMap
()
noexcept
;
...
...
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