From aa08dce7c634b4af4e229e6cb00a41511205aa36 Mon Sep 17 00:00:00 2001 From: StevenNL2000 Date: Sat, 29 Jan 2022 21:03:13 +0100 Subject: [PATCH] Fix detection when browser language is not English --- src/api/reddit/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/reddit/index.js b/src/api/reddit/index.js index 55c5337..a90926b 100644 --- a/src/api/reddit/index.js +++ b/src/api/reddit/index.js @@ -1,6 +1,7 @@ import { fetchJson, chunk } from '../../utils' const baseURL = 'https://api.reddit.com' +const requestSettings = {headers: {"Accept-Language": "en"}} const errorHandler = (error, from) => { console.error(from + ': ' + error) @@ -9,7 +10,7 @@ const errorHandler = (error, from) => { // Return the post itself export const getPost = (subreddit, threadID) => ( - fetchJson(`${baseURL}/comments/${threadID}.json?limit=1`) + fetchJson(`${baseURL}/comments/${threadID}.json?limit=1`, requestSettings) .then(thread => thread[0].data.children[0].data) .catch(error => errorHandler(error, 'reddit.getPost')) ) @@ -23,7 +24,7 @@ export const getPost = (subreddit, threadID) => ( // Helper function that fetches a list of comments const fetchComments = (commentIDs) => ( - fetchJson(`${baseURL}/api/info?id=${commentIDs.map(id => `t1_${id}`).join()}`) + fetchJson(`${baseURL}/api/info?id=${commentIDs.map(id => `t1_${id}`).join()}`, requestSettings) .then(results => results.data.children.map(({data}) => data)) )