leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.13k stars 247 forks source link

Handling db errors (postgressql) #439

Open romanesko opened 8 years ago

romanesko commented 8 years ago

If i throw error in postgres stored procedure like raise exception 'something' using errcode='OF001'; — i get only the message

lps_1 | 2016/05/12 09:13:41 [notice] 21#0: *181 [lua] app.lua:22: /usr/local/share/lua/5.1/lapis/db/postgres.lua:81: select res from test_me() res;
lps_1 | ERROR: something, client: 192.168.99.1, server: , request: "GET /api/test/me HTTP/1.1", host: "192.168.99.100:8080"

Can I get db error code?

leafo commented 8 years ago

I just added db error codes to pgmoon but they aren't exposed in lapis right now. The way lapis handles db error is by calling error which isn't flexible for cases where you might expect an error (eg. handling a unique key insertion failure).

I need to come up with an interface for accessing the error codes that doesn't break existing API and has no serious performance implications.