From c87f0c47cd4fe97f0d3810d3e233f426057a90b7 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Tue, 28 Jan 2014 22:39:53 +0000 Subject: [PATCH] Add sendJsonError --- src/libtomahawk-playdarapi/Api_v1.cpp | 11 +++++++++++ src/libtomahawk-playdarapi/Api_v1.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/libtomahawk-playdarapi/Api_v1.cpp b/src/libtomahawk-playdarapi/Api_v1.cpp index 8871daa90..3b4e835df 100644 --- a/src/libtomahawk-playdarapi/Api_v1.cpp +++ b/src/libtomahawk-playdarapi/Api_v1.cpp @@ -514,3 +514,14 @@ Api_v1::apiCallFailed( QxtWebRequestEvent* event, const QString& method ) { sendPlain404( event, QString( "Method \"%1\" for API 1.5 not found" ).arg( method ), "Method in API 1.5 not found" ); } + + +void +Api_v1::sendJsonError( QxtWebRequestEvent* event, const QString& message ) +{ + QxtWebPageEvent * e = new QxtWebPageEvent( event->sessionID, event->requestID, QString( "{ result: \"error\", error: \"%1\" }" ).arg( message ).toUtf8().constData() ); + e->contentType = "application/json"; + e->status = 500; + e->statusMessage = "Method call failed."; + postEvent( e ); +} diff --git a/src/libtomahawk-playdarapi/Api_v1.h b/src/libtomahawk-playdarapi/Api_v1.h index 843c388d7..c835f9179 100644 --- a/src/libtomahawk-playdarapi/Api_v1.h +++ b/src/libtomahawk-playdarapi/Api_v1.h @@ -82,6 +82,7 @@ public slots: // load an html template from a file, replace args from map // then serve + void sendJsonError( QxtWebRequestEvent* event, const QString& message ); void sendWebpageWithArgs( QxtWebRequestEvent* event, const QString& filenameSource, const QHash< QString, QString >& args ); void index( QxtWebRequestEvent* event );