Fix umbrella "message not found" and invalid msgs
Problem: Any error thrown while looking for thread ancestors was throwing a "message not found" error, which was incorrect and useless. This error caused me to his refresh repeatedly, not understanding that I was publishing multiple messages. Super bad. While investigating this I found that there's a slightly different problem where someone can post an *invalid* message link, which we don't currently have handling for. Solution: Only show that error when it's actually happening, and add support for just ignoring when we see an invalid message link as `root` or `fork`.
This commit is contained in:
parent
bc5c242bfb
commit
9f98ff41c8
|
@ -7,6 +7,7 @@ const prettyMs = require("pretty-ms");
|
|||
const pullParallelMap = require("pull-paramap");
|
||||
const pull = require("pull-stream");
|
||||
const pullSort = require("pull-sort");
|
||||
const ssbRef = require("ssb-ref");
|
||||
|
||||
// HACK: https://github.com/ssbc/ssb-thread-schema/issues/4
|
||||
const isNestedReply = require("ssb-thread-schema/post/nested-reply/validator");
|
||||
|
@ -959,7 +960,7 @@ module.exports = ({ cooler, isPublic }) => {
|
|||
resolve(msg);
|
||||
}
|
||||
|
||||
if (isLooseReply(msg)) {
|
||||
if (isLooseReply(msg) && ssbRef.isMsg(msg.value.content.fork)) {
|
||||
debug("reply, get the parent");
|
||||
try {
|
||||
// It's a message reply, get the parent!
|
||||
|
@ -977,7 +978,10 @@ module.exports = ({ cooler, isPublic }) => {
|
|||
debug(e);
|
||||
resolve(msg);
|
||||
}
|
||||
} else if (isLooseComment(msg)) {
|
||||
} else if (
|
||||
isLooseComment(msg) &&
|
||||
ssbRef.isMsg(msg.value.content.root)
|
||||
) {
|
||||
debug("comment: %s", msg.value.content.root);
|
||||
try {
|
||||
// It's a thread reply, get the parent!
|
||||
|
@ -1113,10 +1117,14 @@ module.exports = ({ cooler, isPublic }) => {
|
|||
|
||||
return await transform(ssb, allMessages, myFeedId);
|
||||
})
|
||||
.catch(() => {
|
||||
throw new Error(
|
||||
"Message not found in the database. You've done nothing wrong. Maybe try again later?"
|
||||
);
|
||||
.catch(err => {
|
||||
if (err.name === "NotFoundError") {
|
||||
throw new Error(
|
||||
"Message not found in the database. You've done nothing wrong. Maybe try again later?"
|
||||
);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
},
|
||||
get: async (msgId, customOptions) => {
|
||||
|
|
Loading…
Reference in New Issue