Skip to content

Commit

Permalink
Merge pull request dbt-labs#2564 from dbt-labs/adjust-discourse-function
Browse files Browse the repository at this point in the history
Adjust discourse function
  • Loading branch information
JKarlavige authored Dec 13, 2022
2 parents 69016e8 + 3849541 commit dcbbdb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion website/docs/docs/build/jinja-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ Writing a macro for the first time? Check whether we've open sourced one in [dbt
```

<Snippet src="discourse-help-feed-header" />
<DiscourseHelpFeed tags="jinja"/>
<DiscourseHelpFeed tags="wee"/>
10 changes: 8 additions & 2 deletions website/functions/get-discourse-topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ async function getDiscourseTopics({ body }) {
// Get topics from Discourse
let { data: { posts, topics } } = await axios.get(`${discourse_endpoint}/search?q=${query}`, { headers })

if(!topics || topics?.length <= 0)
throw new Error('Unable to get results from api request.')
// Return empty array if no topics found for search query
// 200 status is used to prevent triggering Datadog alerts
if(!topics || topics?.length <= 0) {
// Log message with encoded query and end function
console.log('Unable to get results from api request.')
console.log(`Search query: ${query}`)
return returnResponse(200, [])
}

// Set author and like_count for topics if not querying by specific term
let allTopics = topics
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/discourse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const DiscourseFeed = ({
// Set initial min-height
// This is to avoid layout shifts
// which affects Lighthouse performance scores
const setMinHeight = isError
const setMinHeight = isError || !topics?.length > 0
? 'auto'
: 414

Expand Down

0 comments on commit dcbbdb4

Please sign in to comment.