Skip to content

Implement error handling in Chat #67

@zeim839

Description

@zeim839

See components/chat/Chat.tsx:

  useEffect(() => {
    // TODO: HANDLE DATABASE ERRORS.
    const fetchMessages = async () => {
      const msgs = await db.history.readAll()
      setMessages(msgs.map(msg => ({
        role    : msg.role,
        content : msg.content
      } as Message)))
      setIsTyping(false)
    }
    const fetchKey = async () => {
      const keys = await db.keys.readAll()
      if (keys.length === 0) {
        // TODO: SHOW DIALOG
        return
      }
      setClient(new OpenAI({
        baseURL: "https://openrouter.ai/api/v1",
        dangerouslyAllowBrowser: true,
        apiKey: keys[0].key_hash,
      }))
    }
    fetchMessages()
    fetchKey()
  }, [])

We want to implement error messages whenever the app fails to fetch from the database. There are examples of how to do this in:

  • /components/DatabaseProvider.tsx (line 42) -- this one handles custom error messages.
  • /components/editor/Editor.tsx (line 96)
  • /components/chat/Settings.tsx (line 30)

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions