tm.result
One reply shape for callbacks and NUI replies, instead of a local fail in every resource. Shared (client and server).
lua
tm.result.ok({ id = 4 }) -- { ok = true, id = 4 }
tm.result.fail('Missing name.') -- { ok = false, error = 'Missing name.' }
tm.result.fail('Too fast.', { code = 'cooldown' }) -- { ok = false, error = 'Too fast.', code = 'cooldown' }
tm.result.is(value) -- true for a table shaped like a result| Function | Returns |
|---|---|
ok(extra?) | { ok = true, ...extra }. The fields are copied onto a new table, so the table you pass is never changed. ok is always true. |
fail(message?, extra?) | { ok = false, error = message, ...extra }. The default message is 'Something went wrong.'. extra cannot overwrite ok or error. |
is(value) | true when value is a table whose ok is a boolean. |
The failure key is always error. Check what a NUI reads before replacing an older reply that used message.