decentralised sync engine

feat: additional error messages

serenity a62c03b7 77f2d868

Changed files
+19 -3
src
lib
+19 -3
src/lib/handlers/latticeHandshake.ts
···
const recordResult = await getRecordFromFullAtUri(inviteAtUri);
if (!recordResult.ok) {
console.error(
-
`something went wrong fetching the record from the given membership ${JSON.stringify(membership)}`,
);
throw new Error(
JSON.stringify({ error: recordResult.error, membership }),
···
} catch (err) {
return newErrorResponse(500, {
message:
-
"Something went wrong when fetching membership channel records. Check the Shard logs if possible.",
details: err,
});
}
···
const recordResult = await getRecordFromFullAtUri(channelAtUri);
if (!recordResult.ok) {
console.error(
-
`something went wrong fetching the record from the given membership ${JSON.stringify(invite)}`,
);
throw new Error(
JSON.stringify({ error: recordResult.error, invite }),
···
// did of the backlink. if there are any channels described by unauthorised parties, simply drop them.
let mismatchOrIncorrect = false;
const existingShardConnectionShardDids = shardSessions
.keys()
.toArray()
···
routeThroughRecord.uri,
);
if (!routeThroughRecordParseResult.ok) {
mismatchOrIncorrect = true;
return;
}
···
// FIXME: this also assumes that the requesting lattice's DID is a did:web
// see below for the rest of the issues.
if (routeThroughUri.rKey === SERVICE_DID.slice(8)) {
mismatchOrIncorrect = true;
return;
}
const storeAtRecordParseResult = stringToAtUri(storeAtRecord.uri);
if (!storeAtRecordParseResult.ok) {
mismatchOrIncorrect = true;
return;
}
···
if (!storeAtUri.rKey) return;
if (!existingShardConnectionShardDids.includes(storeAtUri.rKey)) {
mismatchOrIncorrect = true;
return;
}
···
return newErrorResponse(400, {
message:
"Channels provided during the handshake had a mismatch between the channel values. Ensure that you are only submitting exactly the channels you have access to.",
});
// yipee, it's a valid request :3
···
const recordResult = await getRecordFromFullAtUri(inviteAtUri);
if (!recordResult.ok) {
console.error(
+
`something went wrong fetching the invite record from the given membership ${JSON.stringify(membership)}`,
);
throw new Error(
JSON.stringify({ error: recordResult.error, membership }),
···
} catch (err) {
return newErrorResponse(500, {
message:
+
"Something went wrong when fetching membership invite records. Check the Shard logs if possible.",
details: err,
});
}
···
const recordResult = await getRecordFromFullAtUri(channelAtUri);
if (!recordResult.ok) {
console.error(
+
`something went wrong fetching the channel record from the given membership ${JSON.stringify(invite)}`,
);
throw new Error(
JSON.stringify({ error: recordResult.error, invite }),
···
// did of the backlink. if there are any channels described by unauthorised parties, simply drop them.
let mismatchOrIncorrect = false;
+
const errors: Array<unknown> = [];
const existingShardConnectionShardDids = shardSessions
.keys()
.toArray()
···
routeThroughRecord.uri,
);
if (!routeThroughRecordParseResult.ok) {
+
errors.push(routeThroughRecordParseResult.error);
mismatchOrIncorrect = true;
return;
}
···
// FIXME: this also assumes that the requesting lattice's DID is a did:web
// see below for the rest of the issues.
if (routeThroughUri.rKey === SERVICE_DID.slice(8)) {
+
errors.push(
+
"Mismatch between claimant lattice and channel routeThrough. Request wants to validate for",
+
routeThroughUri.rKey,
+
", but this lattice is",
+
SERVICE_DID.slice(8),
+
);
mismatchOrIncorrect = true;
return;
}
const storeAtRecordParseResult = stringToAtUri(storeAtRecord.uri);
if (!storeAtRecordParseResult.ok) {
+
errors.push(storeAtRecordParseResult.error);
mismatchOrIncorrect = true;
return;
}
···
if (!storeAtUri.rKey) return;
if (!existingShardConnectionShardDids.includes(storeAtUri.rKey)) {
+
errors.push(
+
"Mismatch between claimant shard and channel storeAt. Request wants to validate for",
+
storeAtUri.rKey,
+
", but this lattice is only allowed to talk to",
+
existingShardConnectionShardDids,
+
);
mismatchOrIncorrect = true;
return;
}
···
return newErrorResponse(400, {
message:
"Channels provided during the handshake had a mismatch between the channel values. Ensure that you are only submitting exactly the channels you have access to.",
+
details: errors,
});
// yipee, it's a valid request :3