input/tidal: parse and report userMessage from error responses
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "TidalTrackRequest.hxx"
|
||||
#include "TidalErrorParser.hxx"
|
||||
#include "lib/yajl/Callbacks.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
@@ -71,8 +72,10 @@ void
|
||||
TidalTrackRequest::OnHeaders(unsigned status,
|
||||
std::multimap<std::string, std::string> &&headers)
|
||||
{
|
||||
if (status != 200)
|
||||
throw FormatRuntimeError("Status %u from Tidal", status);
|
||||
if (status != 200) {
|
||||
error_parser = std::make_unique<TidalErrorParser>(status, headers);
|
||||
return;
|
||||
}
|
||||
|
||||
auto i = headers.find("content-type");
|
||||
if (i == headers.end() || i->second.find("/json") == i->second.npos)
|
||||
@@ -84,12 +87,22 @@ TidalTrackRequest::OnHeaders(unsigned status,
|
||||
void
|
||||
TidalTrackRequest::OnData(ConstBuffer<void> data)
|
||||
{
|
||||
if (error_parser) {
|
||||
error_parser->OnData(data);
|
||||
return;
|
||||
}
|
||||
|
||||
parser.Parse((const unsigned char *)data.data, data.size);
|
||||
}
|
||||
|
||||
void
|
||||
TidalTrackRequest::OnEnd()
|
||||
{
|
||||
if (error_parser) {
|
||||
error_parser->OnEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
parser.CompleteParse();
|
||||
|
||||
if (url.empty())
|
||||
|
||||
Reference in New Issue
Block a user