All Challengesintermediate
Read this error message pattern
Understanding how AI structures error responses from a backend API.
typescript
async function createPost(title: string, content: string) {
if (!title.trim()) {
throw new Error('Title is required')
}
if (content.length < 10) {
throw new Error('Content must be at least 10 characters')
}
const response = await fetch('/api/posts', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title, content })
})
if (!response.ok) {
const error = await response.json()
throw new Error(error.message)
}
return response.json()
}Question
How many different ways can this function throw an error?