box.error.new()
Create an error object with the specified parameters.
Parameters:
-
reason(string) — an error description -
code(integer) — (optional) a numeric code for this error -
type(string) — (optional) an error type
Example 1
local custom_error = box.error.new({ code = 500,reason = 'Internal server error' })box.error(custom_error)--[[---- error: Internal server error...--]]
Example 2: custom type
local custom_error = box.error.new({ code = 500,reason = 'Internal server error',type = 'CustomInternalError' })box.error(custom_error)--[[---- error: Internal server error...--]]
Create an error object with the specified type and description.
-
type(string) — an error type -
reason(string) — an error description -
...— description arguments
Example
local custom_error = box.error.new('CustomInternalError', 'Internal server error')box.error(custom_error)--[[---- error: Internal server error...--]]
Create a predefined Tarantool error specified by its identifier. You can see all Tarantool errors in the errcode.h file.
-
code(number) — a pre-defined error identifier; Lua constants that correspond to those Tarantool errors are defined as members ofbox.error, for example,box.error.NO_SUCH_USER == 45 -
...— description arguments
Example 1: one argument
local custom_error = box.error.new(box.error.NO_SUCH_USER, 'John')box.error(custom_error)--[[---- error: User 'John' is not found...--]]
Example 2: two arguments
local custom_error = box.error.new(box.error.CREATE_SPACE, 'my_space', 'the space already exists')box.error(custom_error)--[[---- error: 'Failed to create space ''my_space'': the space already exists'...--]]