Skip to content

The error thrown by getRoom() in @liveblocks/node encodes an error object in the message key #1978

@robcresswell

Description

@robcresswell

Describe the bug

Initialising a liveblocks/node instance and calling getRoom on a non-existent roomId throws an error. I expected this to be a LiveblocksError class, but it seems to be something else with the following object encoded as a string within error.message:

{
  error: 'ROOM_NOT_FOUND',
  message: 'Room not found',
  suggestion: 'Please use a valid room ID, room IDs are available in the dashboard: https://liveblocks.io/dashboard/rooms',
  docs: 'https://liveblocks.io/docs/api-reference/rest-api-endpoints'
}

This means to check this error, I need to run

JSON.parse(err.message).error === 'ROOM_NOT_FOUND')

which is obviously very fragile

Expected behavior

I'd expect this to return a LiveblocksError, so I can rely on the types. The encoded inner error is very strange, and means I need to write a bunch of defensive / slow code to see if the string can be parsed as a json object.

Environment (please complete the following information):

"@liveblocks/node": "^2.8.1"

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions