Skip to content

Commit efe1605

Browse files
committedAug 22, 2024··
added explicit status codes to api and client
1 parent 6106fdc commit efe1605

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
 

‎api/src/server/v1/index.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const app = new Hono()
8888
const filteredWords = Object.fromEntries(
8989
Object.entries(data).filter(([, value]) => value.usage_category !== "sandbox"),
9090
);
91-
return c.json(filteredWords);
91+
return c.json(filteredWords, 200);
9292
})
9393

9494
.get(
@@ -101,7 +101,7 @@ const app = new Hono()
101101

102102
// FIXME: Remove when packaging script reworked
103103
return word && word.usage_category !== "sandbox"
104-
? c.json({ ok: true as const, data: word })
104+
? c.json({ ok: true as const, data: word }, 200)
105105
: c.json(
106106
{ ok: false as const, message: `Could not find the word ${c.req.param("word")}` },
107107
400,
@@ -115,7 +115,7 @@ const app = new Hono()
115115
const filteredWords = Object.fromEntries(
116116
Object.entries(data).filter(([, value]) => value.usage_category === "sandbox"),
117117
);
118-
return c.json(filteredWords);
118+
return c.json(filteredWords, 200);
119119

120120
// return c.json((await rawData).sandbox);
121121
})
@@ -129,7 +129,7 @@ const app = new Hono()
129129
const word = (await rawData).words[c.req.param("word")];
130130
// FIXME: Remove when packaging script reworked
131131
return word && word.usage_category === "sandbox"
132-
? c.json({ ok: true as const, data: word })
132+
? c.json({ ok: true as const, data: word }, 200)
133133
: c.json(
134134
{
135135
ok: false as const,
@@ -141,7 +141,7 @@ const app = new Hono()
141141
)
142142

143143
.get("/luka_pona/fingerspelling", langValidator, languagesFilter(true), async (c) => {
144-
return c.json((await rawData).fingerspelling);
144+
return c.json((await rawData).fingerspelling, 200);
145145
})
146146

147147
.get(
@@ -153,13 +153,13 @@ const app = new Hono()
153153
const sign = (await rawData).fingerspelling[c.req.param("sign")];
154154

155155
return sign
156-
? c.json({ ok: true as const, data: sign })
156+
? c.json({ ok: true as const, data: sign }, 200)
157157
: c.json({ ok: false as const, message: `Could not find a sign named ${sign}` }, 400);
158158
},
159159
)
160160

161161
.get("/luka_pona/signs", langValidator, languagesFilter(true), async (c) => {
162-
return c.json((await rawData).signs);
162+
return c.json((await rawData).signs, 200);
163163
})
164164

165165
.get(
@@ -171,25 +171,25 @@ const app = new Hono()
171171
const sign = (await rawData).signs[c.req.param("sign")];
172172

173173
return sign
174-
? c.json({ ok: true as const, data: sign })
174+
? c.json({ ok: true as const, data: sign }, 200)
175175
: c.json({ ok: false as const, message: `Could not find a sign named ${sign}` }, 400);
176176
},
177177
)
178178

179179
.get("/fonts", async (c) => {
180-
return c.json((await rawData).fonts);
180+
return c.json((await rawData).fonts, 200);
181181
})
182182

183183
.get("/fonts/:font", zValidator("param", z.object({ font: z.string() })), async (c) => {
184184
const font = (await rawData).fonts[c.req.param("font")];
185185

186186
return font
187-
? c.json({ ok: true as const, data: font })
187+
? c.json({ ok: true as const, data: font }, 200)
188188
: c.json({ ok: false as const, message: `Could not find a font named ${font}` }, 400);
189189
})
190190

191191
.get("/languages", async (c) => {
192-
return c.json((await rawData).languages);
192+
return c.json((await rawData).languages, 200);
193193
})
194194

195195
.get(
@@ -201,7 +201,7 @@ const app = new Hono()
201201
const langId = langIdCoalesce(language, languages);
202202

203203
return langId
204-
? c.json({ ok: true as const, data: languages[langId]! })
204+
? c.json({ ok: true as const, data: languages[langId]! }, 200)
205205
: c.json(
206206
{ ok: false as const, message: `Could not find a language named ${language}` },
207207
400,

0 commit comments

Comments
 (0)