Skip to content

Commit 9715a68

Browse files
committed
make it easier to simulate errors
1 parent 075cb7e commit 9715a68

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

exercises/03.advanced-tools/04.problem.errors/README.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ For this step:
1515
This will make your journaling app more robust and user-friendly, and help LLMs
1616
handle problems gracefully.
1717

18+
<callout-info>
19+
ℹ️ In this exercise, you can simulate an error by trying to submit a tag with
20+
the word "error" in the name.
21+
</callout-info>
22+
1823
Example error response:
1924

2025
```json

exercises/03.advanced-tools/04.problem.errors/src/db/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ export class DB {
155155
// Tag Methods
156156
async createTag(tag: NewTag) {
157157
const validatedTag = newTagSchema.parse(tag)
158+
if (validatedTag.name.toLocaleLowerCase().includes('error')) {
159+
throw new Error('Tag name cannot include the word "error"')
160+
}
158161
const stmt = this.#db.prepare(sql`
159162
INSERT INTO tags (name, description)
160163
VALUES (?, ?)

exercises/03.advanced-tools/04.solution.errors/src/db/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ export class DB {
155155
// Tag Methods
156156
async createTag(tag: NewTag) {
157157
const validatedTag = newTagSchema.parse(tag)
158+
if (validatedTag.name.toLocaleLowerCase().includes('error')) {
159+
throw new Error('Tag name cannot include the word "error"')
160+
}
158161
const stmt = this.#db.prepare(sql`
159162
INSERT INTO tags (name, description)
160163
VALUES (?, ?)

0 commit comments

Comments
 (0)