HaikuDepot: Error Reporting Improvement
When editing a user rating it can be that the user is not authenticated properly or there is some problem. This change improves the error reporting in this situation to give the user a better idea about what is going on. Change-Id: Ib8890c2ea8a7316849486e472aabec05788243ef Reviewed-on: https://review.haiku-os.org/c/haiku/+/2112 Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
6ab29b9387
commit
d17c92f779
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -63,11 +63,15 @@ ServerHelper::AlertServerJsonRpcError(BMessage* message)
|
||||
" in the request was not found on the server.");
|
||||
break;
|
||||
case ERROR_CODE_CAPTCHABADRESPONSE:
|
||||
alertText = B_TRANSLATE("The response to the captcha was incorrect.");
|
||||
alertText = B_TRANSLATE("The response to the captcha was"
|
||||
" incorrect.");
|
||||
break;
|
||||
case ERROR_CODE_AUTHORIZATIONFAILURE:
|
||||
case ERROR_CODE_AUTHORIZATIONRULECONFLICT:
|
||||
alertText = B_TRANSLATE("Authorization or security issue");
|
||||
alertText = B_TRANSLATE("Authorization or security issue. Logout"
|
||||
" and log back in again to check that your password is correct"
|
||||
" and also check that you have agreed to the latest usage"
|
||||
" conditions.");
|
||||
break;
|
||||
default:
|
||||
alertText.SetToFormat(
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Copyright 2016-2019, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2016-2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -437,7 +437,7 @@ WebAppInterface::RetreiveUserRatingForPackageAndVersionByUser(
|
||||
|
||||
status_t
|
||||
WebAppInterface::RetrieveUserDetailForCredentials(
|
||||
const UserCredentials& credentials, UserDetail& userDetail)
|
||||
const UserCredentials& credentials, BMessage& message)
|
||||
{
|
||||
if (!credentials.IsValid()) {
|
||||
debugger("the credentials supplied are invalid so it is not possible "
|
||||
@ -459,15 +459,11 @@ WebAppInterface::RetrieveUserDetailForCredentials(
|
||||
requestEnvelopeWriter.WriteArrayEnd();
|
||||
requestEnvelopeWriter.WriteObjectEnd();
|
||||
|
||||
BMessage responseEnvelopeMessage;
|
||||
status_t result = _SendJsonRequest("user", credentials, requestEnvelopeData,
|
||||
_LengthAndSeekToZero(requestEnvelopeData), NEEDS_AUTHORIZATION,
|
||||
responseEnvelopeMessage);
|
||||
message);
|
||||
// note that the credentials used here are passed in as args.
|
||||
|
||||
if (result == B_OK)
|
||||
result = _UnpackUserDetails(responseEnvelopeMessage, userDetail);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -477,9 +473,9 @@ WebAppInterface::RetrieveUserDetailForCredentials(
|
||||
*/
|
||||
|
||||
status_t
|
||||
WebAppInterface::RetrieveCurrentUserDetail(UserDetail& userDetail)
|
||||
WebAppInterface::RetrieveCurrentUserDetail(BMessage& message)
|
||||
{
|
||||
return RetrieveUserDetailForCredentials(fCredentials, userDetail);
|
||||
return RetrieveUserDetailForCredentials(fCredentials, message);
|
||||
}
|
||||
|
||||
|
||||
@ -489,7 +485,7 @@ WebAppInterface::RetrieveCurrentUserDetail(UserDetail& userDetail)
|
||||
*/
|
||||
|
||||
/*static*/ status_t
|
||||
WebAppInterface::_UnpackUserDetails(BMessage& responseEnvelopeMessage,
|
||||
WebAppInterface::UnpackUserDetail(BMessage& responseEnvelopeMessage,
|
||||
UserDetail& userDetail)
|
||||
{
|
||||
BMessage resultMessage;
|
||||
@ -874,12 +870,12 @@ WebAppInterface::AuthenticateUser(const BString& nickName,
|
||||
*/
|
||||
|
||||
int32
|
||||
WebAppInterface::ErrorCodeFromResponse(BMessage& response)
|
||||
WebAppInterface::ErrorCodeFromResponse(BMessage& responseEnvelopeMessage)
|
||||
{
|
||||
BMessage error;
|
||||
double code;
|
||||
|
||||
if (response.FindMessage("error", &error) == B_OK
|
||||
if (responseEnvelopeMessage.FindMessage("error", &error) == B_OK
|
||||
&& error.FindDouble("code", &code) == B_OK) {
|
||||
return (int32) code;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Copyright 2016-2019, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2016-2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef WEB_APP_INTERFACE_H
|
||||
@ -91,10 +91,10 @@ public:
|
||||
|
||||
status_t RetrieveUserDetailForCredentials(
|
||||
const UserCredentials& credentials,
|
||||
UserDetail& userDetail);
|
||||
BMessage& message);
|
||||
|
||||
status_t RetrieveCurrentUserDetail(
|
||||
UserDetail& userDetail);
|
||||
BMessage& message);
|
||||
|
||||
status_t RetrieveUserUsageConditions(
|
||||
const BString& code,
|
||||
@ -120,12 +120,14 @@ public:
|
||||
const BString& passwordClear,
|
||||
BMessage& message);
|
||||
|
||||
static int32 ErrorCodeFromResponse(BMessage& response);
|
||||
static int32 ErrorCodeFromResponse(
|
||||
BMessage& responseEnvelopeMessage);
|
||||
|
||||
private:
|
||||
static status_t _UnpackUserDetails(
|
||||
static status_t UnpackUserDetail(
|
||||
BMessage& responseEnvelopeMessage,
|
||||
UserDetail& userDetail);
|
||||
private:
|
||||
|
||||
|
||||
status_t _RetrieveUserUsageConditionsMeta(
|
||||
const BString& code, BMessage& message);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2019-2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "MarkupTextView.h"
|
||||
#include "Model.h"
|
||||
#include "UserUsageConditions.h"
|
||||
#include "ServerHelper.h"
|
||||
#include "WebAppInterface.h"
|
||||
|
||||
|
||||
@ -318,36 +319,11 @@ UserUsageConditionsWindow::_FetchUserUsageConditionsCodePerform(
|
||||
switch (fMode) {
|
||||
case LATEST:
|
||||
code.SetTo("");
|
||||
// no code for the latest
|
||||
// no code in order to get the latest
|
||||
return B_OK;
|
||||
case USER:
|
||||
{
|
||||
WebAppInterface interface = fModel.GetWebAppInterface();
|
||||
|
||||
if (interface.Nickname().IsEmpty())
|
||||
debugger("attempt to get user details for the current user, but"
|
||||
" there is no current user");
|
||||
|
||||
status_t result = interface.RetrieveCurrentUserDetail(userDetail);
|
||||
|
||||
if (result == B_OK) {
|
||||
BString userUsageConditionsCode = userDetail.Agreement().Code();
|
||||
if (Logger::IsDebugEnabled()) {
|
||||
printf("the user [%s] has agreed to uuc [%s]\n",
|
||||
interface.Nickname().String(),
|
||||
userUsageConditionsCode.String());
|
||||
}
|
||||
code.SetTo(userUsageConditionsCode);
|
||||
} else {
|
||||
if (Logger::IsDebugEnabled()) {
|
||||
printf("unable to get details of the user [%s]\n",
|
||||
interface.Nickname().String());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
return _FetchUserUsageConditionsCodeForUserPerform(
|
||||
userDetail, code);
|
||||
default:
|
||||
debugger("unhanded mode");
|
||||
return B_ERROR;
|
||||
@ -355,6 +331,60 @@ UserUsageConditionsWindow::_FetchUserUsageConditionsCodePerform(
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
UserUsageConditionsWindow::_FetchUserUsageConditionsCodeForUserPerform(
|
||||
UserDetail& userDetail, BString& code)
|
||||
{
|
||||
WebAppInterface interface = fModel.GetWebAppInterface();
|
||||
|
||||
if (interface.Nickname().IsEmpty())
|
||||
debugger("attempt to get user details for the current user, but"
|
||||
" there is no current user");
|
||||
|
||||
BMessage responseEnvelopeMessage;
|
||||
status_t result = interface.RetrieveCurrentUserDetail(
|
||||
responseEnvelopeMessage);
|
||||
|
||||
if (result == B_OK) {
|
||||
// could be an error or could be a valid response envelope
|
||||
// containing data.
|
||||
switch (interface.ErrorCodeFromResponse(responseEnvelopeMessage)) {
|
||||
case ERROR_CODE_NONE:
|
||||
result = WebAppInterface::UnpackUserDetail(
|
||||
responseEnvelopeMessage, userDetail);
|
||||
break;
|
||||
default:
|
||||
ServerHelper::NotifyServerJsonRpcError(responseEnvelopeMessage);
|
||||
result = B_ERROR;
|
||||
// just any old error to stop
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "an error has arisen communicating with the"
|
||||
" server to obtain data for a user's user usage conditions"
|
||||
" [%s]\n", strerror(result));
|
||||
ServerHelper::NotifyTransportError(result);
|
||||
}
|
||||
|
||||
if (result == B_OK) {
|
||||
BString userUsageConditionsCode = userDetail.Agreement().Code();
|
||||
if (Logger::IsDebugEnabled()) {
|
||||
printf("the user [%s] has agreed to uuc [%s]\n",
|
||||
interface.Nickname().String(),
|
||||
userUsageConditionsCode.String());
|
||||
}
|
||||
code.SetTo(userUsageConditionsCode);
|
||||
} else {
|
||||
if (Logger::IsDebugEnabled()) {
|
||||
printf("unable to get details of the user [%s]\n",
|
||||
interface.Nickname().String());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
UserUsageConditionsWindow::_NotifyFetchProblem()
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2019-2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef USER_USAGE_CONDITIONS_WINDOW_H
|
||||
@ -54,6 +54,8 @@ private:
|
||||
void _FetchDataPerform();
|
||||
status_t _FetchUserUsageConditionsCodePerform(
|
||||
UserDetail& userDetail, BString& code);
|
||||
status_t _FetchUserUsageConditionsCodeForUserPerform(
|
||||
UserDetail& userDetail, BString& code);
|
||||
void _NotifyFetchProblem();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user