Skip to content

Commit a5dbd96

Browse files
committed
fix(reddit): add HTTP error handling to GET tools
Add !response.ok guards to get_me, get_user, get_subreddit_info, and get_messages to return success: false on non-2xx responses instead of silently returning empty data with success: true.
1 parent e751d6c commit a5dbd96

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

apps/sim/tools/reddit/get_me.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ export const getMeTool: ToolConfig<RedditGetMeParams, RedditUserResponse> = {
4040
transformResponse: async (response: Response) => {
4141
const data = await response.json()
4242

43+
if (!response.ok) {
44+
return {
45+
success: false,
46+
output: {
47+
id: '',
48+
name: '',
49+
created_utc: 0,
50+
link_karma: 0,
51+
comment_karma: 0,
52+
total_karma: 0,
53+
is_gold: false,
54+
is_mod: false,
55+
has_verified_email: false,
56+
icon_img: '',
57+
},
58+
}
59+
}
60+
4361
return {
4462
success: true,
4563
output: {

apps/sim/tools/reddit/get_messages.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export const getMessagesTool: ToolConfig<RedditGetMessagesParams, RedditMessages
9999
transformResponse: async (response: Response) => {
100100
const data = await response.json()
101101

102+
if (!response.ok) {
103+
return {
104+
success: false,
105+
output: { messages: [], after: null, before: null },
106+
}
107+
}
108+
102109
const messages =
103110
data.data?.children?.map((child: any) => {
104111
const msg = child.data || {}

apps/sim/tools/reddit/get_subreddit_info.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ export const getSubredditInfoTool: ToolConfig<
5555

5656
transformResponse: async (response: Response) => {
5757
const data = await response.json()
58+
59+
if (!response.ok) {
60+
return {
61+
success: false,
62+
output: {
63+
id: '',
64+
name: '',
65+
display_name: '',
66+
title: '',
67+
description: '',
68+
public_description: '',
69+
subscribers: 0,
70+
accounts_active: 0,
71+
created_utc: 0,
72+
over18: false,
73+
lang: '',
74+
subreddit_type: '',
75+
url: '',
76+
icon_img: null,
77+
banner_img: null,
78+
},
79+
}
80+
}
81+
5882
const sub = data.data || data
5983

6084
return {

apps/sim/tools/reddit/get_user.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ export const getUserTool: ToolConfig<RedditGetUserParams, RedditUserResponse> =
4848

4949
transformResponse: async (response: Response) => {
5050
const data = await response.json()
51+
52+
if (!response.ok) {
53+
return {
54+
success: false,
55+
output: {
56+
id: '',
57+
name: '',
58+
created_utc: 0,
59+
link_karma: 0,
60+
comment_karma: 0,
61+
total_karma: 0,
62+
is_gold: false,
63+
is_mod: false,
64+
has_verified_email: false,
65+
icon_img: '',
66+
},
67+
}
68+
}
69+
5170
const user = data.data || data
5271

5372
return {

0 commit comments

Comments
 (0)