diff --git a/components/ReplyItem.js b/components/ReplyItem.js index 8753cbfe..e4669f99 100644 --- a/components/ReplyItem.js +++ b/components/ReplyItem.js @@ -61,10 +61,12 @@ ReplyItem.fragments = { type createdAt user { + id name } articleReplies(status: NORMAL) { articleId + replyId } } `, diff --git a/constants/errors.js b/constants/errors.js index 02b4ebf6..e563323b 100644 --- a/constants/errors.js +++ b/constants/errors.js @@ -1,2 +1,6 @@ // Matches setup in rumors-api export const AUTH_ERROR_MSG = 'userId is not set via query string.'; + +// Matches setup in rumors-api +export const NO_USER_FOR_ARTICLE = + 'fromUserOfArticleId does not match any existing articles'; diff --git a/lib/rollbar.js b/lib/rollbar.js index e5acea14..38e90bd2 100644 --- a/lib/rollbar.js +++ b/lib/rollbar.js @@ -5,6 +5,7 @@ */ import Rollbar from 'rollbar'; import getConfig from 'next/config'; +import { NO_USER_FOR_ARTICLE } from 'constants/errors'; if (typeof window !== 'undefined') { throw new Error( @@ -25,6 +26,7 @@ const rollbar = new Rollbar({ captureUncaught: true, captureUnhandledRejections: true, nodeSourceMaps: true, + ignoredMessages: [NO_USER_FOR_ARTICLE], }); export default rollbar; diff --git a/pages/_document.js b/pages/_document.js index f9cc7b70..ec2942e0 100644 --- a/pages/_document.js +++ b/pages/_document.js @@ -2,7 +2,7 @@ import React from 'react'; import Document, { Head, Main, NextScript } from 'next/document'; import getConfig from 'next/config'; import { ServerStyleSheets } from '@material-ui/styles'; -import { AUTH_ERROR_MSG } from 'constants/errors'; +import { AUTH_ERROR_MSG, NO_USER_FOR_ARTICLE } from 'constants/errors'; import theme from 'lib/theme'; import agent from 'lib/stackimpact'; import rollbar from 'lib/rollbar'; @@ -60,7 +60,7 @@ class MyDocument extends Document { captureUncaught: true, captureUnhandledRejections: true, payload: { environment: "${PUBLIC_ROLLBAR_ENV}" }, - ignoredMessages: ["${AUTH_ERROR_MSG}"], + ignoredMessages: ["${AUTH_ERROR_MSG}", "${NO_USER_FOR_ARTICLE}"], }; ${rollbarSnippet} `, diff --git a/pages/articles.js b/pages/articles.js index a026f7ec..d447eaaf 100644 --- a/pages/articles.js +++ b/pages/articles.js @@ -195,7 +195,8 @@ function ArticleListPage() { const { loading, - data: { ListArticles: articleData }, + data: listArticlesData, + error: listArticlesError, } = useQuery(LIST_ARTICLES, { variables: { ...listQueryVars, @@ -207,19 +208,21 @@ function ArticleListPage() { // Separate these stats query so that it will be cached by apollo-client and sends no network request // on page change, but still works when filter options are updated. // - const { - loading: statsLoading, - data: { ListArticles: statsData }, - } = useQuery(LIST_STAT, { + const { loading: statsLoading, data: listStatData } = useQuery(LIST_STAT, { variables: listQueryVars, }); + // List data + const statsData = listStatData?.ListArticles || {}; + const articleEdges = listArticlesData?.ListArticles?.edges || []; + + // Flags const showOneTimeMessages = +query.replyRequestCount === 1; - const searchedArticleEdge = (articleData?.edges || []).find( + const searchedArticleEdge = articleEdges.find( ({ node: { id } }) => id === query.searchUserByArticleId ); const searchedUserArticleElem = ( - + {ellipsis(searchedArticleEdge?.node?.text || '', { wordCount: 15 })} ); @@ -304,15 +307,17 @@ function ArticleListPage() { {loading ? ( 'Loading....' + ) : listArticlesError ? ( + listArticlesError.toString() ) : ( <>