jbochi / lua-resty-cassandra

Pure Lua Cassandra client using CQL binary protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose returned error code

thibaultcha opened this issue · comments

In order to take appropriate actions when an error occurs, it would be nice to expose the error code of an error.

Ex: currently the module is returning:

Cassandra returned error (Unprepared): \"Prepared query with ID 1a1c267a69878d0062b3802883fcbd48 not found (either the query was not prepared on this host (maybe the host has been restarted?) or you have prepared too many queries and it has been evicted from the internal cache)

But in order to prepare the statement, we need to detect the type of the error, and currently, the only way of doing so is parsing or comparing the error string.

Since this would not be coherent with the errors returned by the cosocket API we are wrapping (which are only strings) I am not sure about this. But at the same time, detecting the error type from the string seems weird. What do you think?

That's a good question. It's possible to return a table instead of a string as the error "message". The table could then contain the error code and the the message as string. The table could also have the metamethod __tostring to make it compatible with current code. What do you think?

It's what I decided to go with on Kong's errors, here and it indeed works pretty well so far!