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 <[email protected]>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2018, Andrew Lindesay <[email protected]>.
|
* Copyright 2017-2020, Andrew Lindesay <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* 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.");
|
" in the request was not found on the server.");
|
||||||
break;
|
break;
|
||||||
case ERROR_CODE_CAPTCHABADRESPONSE:
|
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;
|
break;
|
||||||
case ERROR_CODE_AUTHORIZATIONFAILURE:
|
case ERROR_CODE_AUTHORIZATIONFAILURE:
|
||||||
case ERROR_CODE_AUTHORIZATIONRULECONFLICT:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
alertText.SetToFormat(
|
alertText.SetToFormat(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014, Stephan Aßmus <[email protected]>.
|
* Copyright 2014, Stephan Aßmus <[email protected]>.
|
||||||
* Copyright 2016-2019, Andrew Lindesay <[email protected]>.
|
* Copyright 2016-2020, Andrew Lindesay <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -437,7 +437,7 @@ WebAppInterface::RetreiveUserRatingForPackageAndVersionByUser(
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
WebAppInterface::RetrieveUserDetailForCredentials(
|
WebAppInterface::RetrieveUserDetailForCredentials(
|
||||||
const UserCredentials& credentials, UserDetail& userDetail)
|
const UserCredentials& credentials, BMessage& message)
|
||||||
{
|
{
|
||||||
if (!credentials.IsValid()) {
|
if (!credentials.IsValid()) {
|
||||||
debugger("the credentials supplied are invalid so it is not possible "
|
debugger("the credentials supplied are invalid so it is not possible "
|
||||||
@@ -459,15 +459,11 @@ WebAppInterface::RetrieveUserDetailForCredentials(
|
|||||||
requestEnvelopeWriter.WriteArrayEnd();
|
requestEnvelopeWriter.WriteArrayEnd();
|
||||||
requestEnvelopeWriter.WriteObjectEnd();
|
requestEnvelopeWriter.WriteObjectEnd();
|
||||||
|
|
||||||
BMessage responseEnvelopeMessage;
|
|
||||||
status_t result = _SendJsonRequest("user", credentials, requestEnvelopeData,
|
status_t result = _SendJsonRequest("user", credentials, requestEnvelopeData,
|
||||||
_LengthAndSeekToZero(requestEnvelopeData), NEEDS_AUTHORIZATION,
|
_LengthAndSeekToZero(requestEnvelopeData), NEEDS_AUTHORIZATION,
|
||||||
responseEnvelopeMessage);
|
message);
|
||||||
// note that the credentials used here are passed in as args.
|
// note that the credentials used here are passed in as args.
|
||||||
|
|
||||||
if (result == B_OK)
|
|
||||||
result = _UnpackUserDetails(responseEnvelopeMessage, userDetail);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,9 +473,9 @@ WebAppInterface::RetrieveUserDetailForCredentials(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
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
|
/*static*/ status_t
|
||||||
WebAppInterface::_UnpackUserDetails(BMessage& responseEnvelopeMessage,
|
WebAppInterface::UnpackUserDetail(BMessage& responseEnvelopeMessage,
|
||||||
UserDetail& userDetail)
|
UserDetail& userDetail)
|
||||||
{
|
{
|
||||||
BMessage resultMessage;
|
BMessage resultMessage;
|
||||||
@@ -874,12 +870,12 @@ WebAppInterface::AuthenticateUser(const BString& nickName,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int32
|
int32
|
||||||
WebAppInterface::ErrorCodeFromResponse(BMessage& response)
|
WebAppInterface::ErrorCodeFromResponse(BMessage& responseEnvelopeMessage)
|
||||||
{
|
{
|
||||||
BMessage error;
|
BMessage error;
|
||||||
double code;
|
double code;
|
||||||
|
|
||||||
if (response.FindMessage("error", &error) == B_OK
|
if (responseEnvelopeMessage.FindMessage("error", &error) == B_OK
|
||||||
&& error.FindDouble("code", &code) == B_OK) {
|
&& error.FindDouble("code", &code) == B_OK) {
|
||||||
return (int32) code;
|
return (int32) code;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014, Stephan Aßmus <[email protected]>.
|
* Copyright 2014, Stephan Aßmus <[email protected]>.
|
||||||
* Copyright 2016-2019, Andrew Lindesay <[email protected]>.
|
* Copyright 2016-2020, Andrew Lindesay <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef WEB_APP_INTERFACE_H
|
#ifndef WEB_APP_INTERFACE_H
|
||||||
@@ -91,10 +91,10 @@ public:
|
|||||||
|
|
||||||
status_t RetrieveUserDetailForCredentials(
|
status_t RetrieveUserDetailForCredentials(
|
||||||
const UserCredentials& credentials,
|
const UserCredentials& credentials,
|
||||||
UserDetail& userDetail);
|
BMessage& message);
|
||||||
|
|
||||||
status_t RetrieveCurrentUserDetail(
|
status_t RetrieveCurrentUserDetail(
|
||||||
UserDetail& userDetail);
|
BMessage& message);
|
||||||
|
|
||||||
status_t RetrieveUserUsageConditions(
|
status_t RetrieveUserUsageConditions(
|
||||||
const BString& code,
|
const BString& code,
|
||||||
@@ -120,12 +120,14 @@ public:
|
|||||||
const BString& passwordClear,
|
const BString& passwordClear,
|
||||||
BMessage& message);
|
BMessage& message);
|
||||||
|
|
||||||
static int32 ErrorCodeFromResponse(BMessage& response);
|
static int32 ErrorCodeFromResponse(
|
||||||
|
BMessage& responseEnvelopeMessage);
|
||||||
|
|
||||||
private:
|
static status_t UnpackUserDetail(
|
||||||
static status_t _UnpackUserDetails(
|
|
||||||
BMessage& responseEnvelopeMessage,
|
BMessage& responseEnvelopeMessage,
|
||||||
UserDetail& userDetail);
|
UserDetail& userDetail);
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
status_t _RetrieveUserUsageConditionsMeta(
|
status_t _RetrieveUserUsageConditionsMeta(
|
||||||
const BString& code, BMessage& message);
|
const BString& code, BMessage& message);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019, Andrew Lindesay <[email protected]>.
|
* Copyright 2019-2020, Andrew Lindesay <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "MarkupTextView.h"
|
#include "MarkupTextView.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
#include "UserUsageConditions.h"
|
#include "UserUsageConditions.h"
|
||||||
|
#include "ServerHelper.h"
|
||||||
#include "WebAppInterface.h"
|
#include "WebAppInterface.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -318,36 +319,11 @@ UserUsageConditionsWindow::_FetchUserUsageConditionsCodePerform(
|
|||||||
switch (fMode) {
|
switch (fMode) {
|
||||||
case LATEST:
|
case LATEST:
|
||||||
code.SetTo("");
|
code.SetTo("");
|
||||||
// no code for the latest
|
// no code in order to get the latest
|
||||||
return B_OK;
|
return B_OK;
|
||||||
case USER:
|
case USER:
|
||||||
{
|
return _FetchUserUsageConditionsCodeForUserPerform(
|
||||||
WebAppInterface interface = fModel.GetWebAppInterface();
|
userDetail, code);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
debugger("unhanded mode");
|
debugger("unhanded mode");
|
||||||
return B_ERROR;
|
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
|
void
|
||||||
UserUsageConditionsWindow::_NotifyFetchProblem()
|
UserUsageConditionsWindow::_NotifyFetchProblem()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019, Andrew Lindesay <[email protected]>.
|
* Copyright 2019-2020, Andrew Lindesay <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef USER_USAGE_CONDITIONS_WINDOW_H
|
#ifndef USER_USAGE_CONDITIONS_WINDOW_H
|
||||||
@@ -54,6 +54,8 @@ private:
|
|||||||
void _FetchDataPerform();
|
void _FetchDataPerform();
|
||||||
status_t _FetchUserUsageConditionsCodePerform(
|
status_t _FetchUserUsageConditionsCodePerform(
|
||||||
UserDetail& userDetail, BString& code);
|
UserDetail& userDetail, BString& code);
|
||||||
|
status_t _FetchUserUsageConditionsCodeForUserPerform(
|
||||||
|
UserDetail& userDetail, BString& code);
|
||||||
void _NotifyFetchProblem();
|
void _NotifyFetchProblem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user