aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-11-04 20:20:11 +0100
committerFlorian Dold <florian@dold.me>2021-11-04 20:20:11 +0100
commit9e379ef399a032a3fbd86d18ede867aaf6a1821f (patch)
treeb5595027d36ab70d4a1ecd818d74f251af677ca9 /packages
parentb94dc8f9e26219b1f54e1456f8d7be00d333aa80 (diff)
anastasis-core: truth payments, status codes
Diffstat (limited to 'packages')
-rw-r--r--packages/anastasis-core/src/index.ts34
1 files changed, 28 insertions, 6 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts
index f77707ae1..238b658a0 100644
--- a/packages/anastasis-core/src/index.ts
+++ b/packages/anastasis-core/src/index.ts
@@ -466,6 +466,8 @@ async function uploadSecret(
const truthMetadataMap = recoveryData.truth_metadata;
const rd = recoveryData.recovery_document;
+ const truthPayUris: string[] = [];
+
for (const truthKey of Object.keys(truthMetadataMap)) {
const tm = truthMetadataMap[truthKey];
const pol = state.policies![tm.policy_index];
@@ -501,12 +503,31 @@ async function uploadSecret(
body: JSON.stringify(tur),
});
- if (resp.status !== 204) {
- return {
- code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
- hint: `could not upload truth (HTTP status ${resp.status})`,
- };
+ if (resp.status === HttpStatusCode.NoContent) {
+ continue;
+ }
+ if (resp.status === HttpStatusCode.PaymentRequired) {
+ const talerPayUri = resp.headers.get("Taler");
+ if (!talerPayUri) {
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_BACKEND_FAILURE,
+ hint: `payment requested, but no taler://pay URI given`,
+ };
+ }
+ truthPayUris.push(talerPayUri);
}
+ return {
+ code: TalerErrorCode.ANASTASIS_REDUCER_NETWORK_FAILED,
+ hint: `could not upload truth (HTTP status ${resp.status})`,
+ };
+ }
+
+ if (truthPayUris.length > 0) {
+ return {
+ ...state,
+ backup_state: BackupStates.TruthsPaying,
+ payments: truthPayUris,
+ };
}
const successDetails: SuccessDetails = {};
@@ -537,7 +558,7 @@ async function uploadSecret(
body: decodeCrock(encRecoveryDoc),
},
);
- if (resp.status === HttpStatusCode.Accepted) {
+ if (resp.status === HttpStatusCode.NoContent) {
let policyVersion = 0;
let policyExpiration: Timestamp = { t_ms: 0 };
try {
@@ -554,6 +575,7 @@ async function uploadSecret(
policy_version: policyVersion,
policy_expiration: policyExpiration,
};
+ continue;
}
if (resp.status === HttpStatusCode.PaymentRequired) {
const talerPayUri = resp.headers.get("Taler");