mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-22 08:28:35 +00:00
Show proper error messages for pg query errors
This commit is contained in:
parent
efc704b17a
commit
bd470f7d01
1 changed files with 24 additions and 10 deletions
|
|
@ -22,18 +22,32 @@ class PostgresqlQueryService
|
|||
|
||||
def process
|
||||
|
||||
connection = get_cached_connection(data_source)
|
||||
connection = create_connection unless connection
|
||||
error = false
|
||||
|
||||
query_text = ''
|
||||
query_text = if options['mode'] === 'gui'
|
||||
send("generate_#{options['operation']}_query", options)
|
||||
else
|
||||
options['query']
|
||||
end
|
||||
begin
|
||||
connection = get_cached_connection(data_source)
|
||||
connection = create_connection unless connection
|
||||
|
||||
result = connection.exec(query_text)
|
||||
{ status: 'success', data: result.to_a }
|
||||
|
||||
query_text = ''
|
||||
query_text = if options['mode'] === 'gui'
|
||||
send("generate_#{options['operation']}_query", options)
|
||||
else
|
||||
options['query']
|
||||
end
|
||||
|
||||
result = connection.exec(query_text)
|
||||
|
||||
rescue StandardError => e
|
||||
puts e
|
||||
error = { message: e.message }
|
||||
end
|
||||
|
||||
if error
|
||||
{ status: 'error', code: 500, message: error[:message], data: error }
|
||||
else
|
||||
{ status: 'success', data: result.to_a }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
Loading…
Reference in a new issue