-
-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved error messaging for Update Channel API #5429
Changes from 4 commits
c60a514
7641f87
a0d97f0
f7e250a
ec59fff
c2cc573
879a633
cda1c66
e6d9b96
4e5d031
5ed0c9e
6997f26
f258c00
6f10bac
a02c0f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,8 @@ QString setTitle(const CommandContext &ctx) | |
return ""; | ||
} | ||
|
||
auto status = ctx.twitchChannel->accessStreamStatus(); | ||
auto title = ctx.words.mid(1).join(" "); | ||
|
||
getHelix()->updateChannel( | ||
ctx.twitchChannel->roomId(), "", "", title, | ||
[channel{ctx.channel}, title](const auto &result) { | ||
|
@@ -40,10 +40,46 @@ QString setTitle(const CommandContext &ctx) | |
channel->addMessage( | ||
makeSystemMessage(QString("Updated title to %1").arg(title))); | ||
}, | ||
[channel{ctx.channel}] { | ||
channel->addMessage( | ||
makeSystemMessage("Title update failed! Are you " | ||
"missing the required scope?")); | ||
[channel{ctx.channel}](auto error, auto message) { | ||
QString errorMessage = QString("Failed to set title - "); | ||
|
||
using Error = HelixUpdateChannelError; | ||
|
||
switch(error) | ||
{ | ||
case Error::UserMissingScope: { | ||
errorMessage += "Missing required scope. " | ||
"Re-login with your " | ||
"account and try again."; | ||
} | ||
break; | ||
|
||
case Error::UserNotAuthorized: { | ||
errorMessage += "You must be the broadcaster " | ||
"to set the title."; | ||
} | ||
break; | ||
|
||
case Error::Ratelimited: { | ||
errorMessage += | ||
"You are being ratelimited by Twitch. Try " | ||
"again in a few seconds."; | ||
} | ||
break; | ||
|
||
case Error::Forwarded: { | ||
errorMessage += message; | ||
} | ||
break; | ||
|
||
case Error::Unknown: | ||
default: { | ||
errorMessage += "An unknown error has occured."; | ||
} | ||
break; | ||
} | ||
|
||
channel->addMessage(makeSystemMessage(errorMessage)); | ||
}); | ||
|
||
return ""; | ||
|
@@ -105,10 +141,46 @@ QString setGame(const CommandContext &ctx) | |
channel->addMessage(makeSystemMessage( | ||
QString("Updated game to %1").arg(matchedGame.name))); | ||
}, | ||
[channel] { | ||
channel->addMessage( | ||
makeSystemMessage("Game update failed! Are you " | ||
"missing the required scope?")); | ||
[channel](auto error, auto message) { | ||
QString errorMessage = QString("Failed to set game - "); | ||
|
||
using Error = HelixUpdateChannelError; | ||
|
||
switch(error) | ||
{ | ||
case Error::UserMissingScope: { | ||
errorMessage += "Missing required scope. " | ||
"Re-login with your " | ||
"account and try again."; | ||
} | ||
break; | ||
|
||
case Error::UserNotAuthorized: { | ||
errorMessage += "You must be the broadcaster " | ||
"to set the game."; | ||
} | ||
break; | ||
|
||
case Error::Ratelimited: { | ||
errorMessage += | ||
"You are being ratelimited by Twitch. Try " | ||
"again in a few seconds."; | ||
} | ||
break; | ||
|
||
case Error::Forwarded: { | ||
errorMessage += message; | ||
} | ||
break; | ||
|
||
case Error::Unknown: | ||
default: { | ||
errorMessage += "An unknown error has occured."; | ||
} | ||
break; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is almost identical to the code above and should be refactored into a function (in an anonymous namespace above |
||
|
||
channel->addMessage(makeSystemMessage(errorMessage)); | ||
}); | ||
}, | ||
[channel{ctx.channel}] { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -616,8 +616,11 @@ void Helix::unblockUser(QString targetUserId, const QObject *caller, | |
void Helix::updateChannel(QString broadcasterId, QString gameId, | ||
QString language, QString title, | ||
std::function<void(NetworkResult)> successCallback, | ||
HelixFailureCallback failureCallback) | ||
FailureCallback<HelixUpdateChannelError, QString> failureCallback) | ||
{ | ||
|
||
using Error = HelixUpdateChannelError; | ||
|
||
QUrlQuery urlQuery; | ||
auto obj = QJsonObject(); | ||
if (!gameId.isEmpty()) | ||
|
@@ -646,7 +649,61 @@ void Helix::updateChannel(QString broadcasterId, QString gameId, | |
successCallback(result); | ||
}) | ||
.onError([failureCallback](NetworkResult result) { | ||
failureCallback(); | ||
if (!result.status()) | ||
{ | ||
failureCallback(Error::Unknown, result.formatError()); | ||
return; | ||
} | ||
|
||
auto obj = result.parseJson(); | ||
auto message = obj.value("message").toString(); | ||
|
||
switch(*result.status()) | ||
{ | ||
case 401: { | ||
if (message.startsWith("Missing scope", | ||
Qt::CaseInsensitive)) | ||
{ | ||
failureCallback(Error::UserMissingScope, message); | ||
} | ||
else if (message.compare( | ||
"The ID in broadcaster_id must match the user " | ||
"ID found in the request's OAuth token.", | ||
Qt::CaseInsensitive) == 0) | ||
{ | ||
failureCallback(Error::UserNotAuthorized, message); | ||
} | ||
else | ||
{ | ||
failureCallback(Error::Forwarded, message); | ||
} | ||
} | ||
break; | ||
|
||
case 400: | ||
case 403: { | ||
failureCallback(Error::Forwarded, message); | ||
} | ||
break; | ||
|
||
case 409: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong. Shouldn't 409 forward the message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the Modify Channel Information docs, 409 for this endpoint will give a Too Many Requests response when trying to see the Branded Content flag too frequently, which wouldn't be hit by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right. I read Too Many Requests and thought it would be 429. Probably should say 409 Conflict in the docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it looks like it's just a typo in the docs, I'll remove the 409, and leave it to just 429. |
||
case 429: { | ||
failureCallback(Error::Ratelimited, message); | ||
} | ||
break; | ||
|
||
case 500: { | ||
failureCallback(Error::Unknown, message); | ||
} | ||
|
||
default: { | ||
qCDebug(chatterinoTwitch) | ||
<< "Helix update channel, unhandled error data:" << result.formatError() | ||
<< result.getData() << obj; | ||
failureCallback(Error::Unknown, message); | ||
} | ||
break; | ||
} | ||
}) | ||
.execute(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should include the message - like "Failed to set title - An unknown error has occurred ({message})" (there's also a typo in occured → occurred, which is also present in the error handling of
manageAutoModMessages
and the comment forsecondsSinceDisconnect
).