Skip to content

Commit c040b73

Browse files
authored
feat(reporter): customers can now catch every errors thrown by forest (#519)
1 parent 6cbfb61 commit c040b73

27 files changed

+91
-2
lines changed

app/controllers/forest_liana/actions_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def get_smart_action_hook_request
55
begin
66
params[:data][:attributes]
77
rescue => error
8+
FOREST_REPORTER.report error
89
FOREST_LOGGER.error "Smart Action hook request error: #{error}"
910
{}
1011
end
@@ -19,6 +20,7 @@ def get_action(collection_name)
1920
begin
2021
collection.actions.find {|action| ActiveSupport::Inflector.parameterize(action.name) == params[:action_name]}
2122
rescue => error
23+
FOREST_REPORTER.report error
2224
FOREST_LOGGER.error "Smart Action get action retrieval error: #{error}"
2325
nil
2426
end
@@ -57,6 +59,7 @@ def handle_result(result, action)
5759
rescue ForestLiana::Errors::SmartActionInvalidFieldError => invalid_field_error
5860
FOREST_LOGGER.warn invalid_field_error.message
5961
rescue ForestLiana::Errors::SmartActionInvalidFieldHookError => invalid_hook_error
62+
FOREST_REPORTER.report invalid_hook_error
6063
FOREST_LOGGER.error invalid_hook_error.message
6164
return render status: 500, json: { error: invalid_hook_error.message }
6265
end

app/controllers/forest_liana/associations_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def index
1818
format.csv { render_csv(getter, @association.klass) }
1919
end
2020
rescue => error
21+
FOREST_REPORTER.report error
2122
FOREST_LOGGER.error "Association Index error: #{error}\n#{format_stacktrace(error)}"
2223
internal_server_error
2324
end
@@ -30,6 +31,7 @@ def count
3031

3132
render serializer: nil, json: { count: getter.records_count }
3233
rescue => error
34+
FOREST_REPORTER.report error
3335
FOREST_LOGGER.error "Association Index Count error: #{error}\n#{format_stacktrace(error)}"
3436
internal_server_error
3537
end
@@ -47,6 +49,7 @@ def update
4749
head :no_content
4850
end
4951
rescue => error
52+
FOREST_REPORTER.report error
5053
FOREST_LOGGER.error "Association Update error: #{error}\n#{format_stacktrace(error)}"
5154
internal_server_error
5255
end
@@ -59,6 +62,7 @@ def associate
5962

6063
head :no_content
6164
rescue => error
65+
FOREST_REPORTER.report error
6266
FOREST_LOGGER.error "Association Associate error: #{error}\n#{format_stacktrace(error)}"
6367
internal_server_error
6468
end

app/controllers/forest_liana/base_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def reject_unauthorized_ip
3030
}])
3131
render(serializer: nil, json: error_data, status: exception.status)
3232
rescue => exception
33+
FOREST_REPORTER.report exception
3334
FOREST_LOGGER.error(exception)
3435
FOREST_LOGGER.error(exception.backtrace.join("\n"))
3536
render(serializer: nil, json: nil, status: :internal_server_error)

app/controllers/forest_liana/resources_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def index
4747
}])
4848
render(serializer: nil, json: error_data, status: error.status)
4949
rescue => error
50+
FOREST_REPORTER.report error
5051
FOREST_LOGGER.error "Records Index error: #{error}\n#{format_stacktrace(error)}"
5152
internal_server_error
5253
end
@@ -79,6 +80,7 @@ def count
7980
}])
8081
render(serializer: nil, json: error_data, status: error.status)
8182
rescue => error
83+
FOREST_REPORTER.report error
8284
FOREST_LOGGER.error "Records Index Count error: #{error}\n#{format_stacktrace(error)}"
8385
internal_server_error
8486
end
@@ -96,6 +98,7 @@ def show
9698
rescue ActiveRecord::RecordNotFound
9799
render serializer: nil, json: { status: 404 }, status: :not_found
98100
rescue => error
101+
FOREST_REPORTER.report error
99102
FOREST_LOGGER.error "Record Show error: #{error}\n#{format_stacktrace(error)}"
100103
internal_server_error
101104
end
@@ -119,6 +122,7 @@ def create
119122
creator.record.errors), status: 400
120123
end
121124
rescue => error
125+
FOREST_REPORTER.report error
122126
FOREST_LOGGER.error "Record Create error: #{error}\n#{format_stacktrace(error)}"
123127
internal_server_error
124128
end
@@ -142,6 +146,7 @@ def update
142146
updater.record.errors), status: 400
143147
end
144148
rescue => error
149+
FOREST_REPORTER.report error
145150
FOREST_LOGGER.error "Record Update error: #{error}\n#{format_stacktrace(error)}"
146151
internal_server_error
147152
end
@@ -162,6 +167,7 @@ def destroy
162167

163168
head :no_content
164169
rescue => error
170+
FOREST_REPORTER.report error
165171
FOREST_LOGGER.error "Record Destroy error: #{error}\n#{format_stacktrace(error)}"
166172
internal_server_error
167173
end
@@ -175,6 +181,7 @@ def destroy_bulk
175181

176182
head :no_content
177183
rescue => error
184+
FOREST_REPORTER.report error
178185
FOREST_LOGGER.error "Records Destroy error: #{error}\n#{format_stacktrace(error)}"
179186
internal_server_error
180187
end
@@ -190,6 +197,7 @@ def find_resource
190197
render serializer: nil, json: { status: 404 }, status: :not_found
191198
end
192199
rescue => error
200+
FOREST_REPORTER.report error
193201
FOREST_LOGGER.error "Find Collection error: #{error}\n#{format_stacktrace(error)}"
194202
render serializer: nil, json: { status: 404 }, status: :not_found
195203
end

app/controllers/forest_liana/router.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def call(env)
3939

4040
controller.action(action.to_sym).call(env)
4141
rescue NoMethodError => exception
42+
FOREST_REPORTER.report exception
4243
FOREST_LOGGER.error "Routing error: #{exception}\n#{exception.backtrace.join("\n\t")}"
4344
ForestLiana::BaseController.action(:route_not_found).call(env)
4445
end

app/controllers/forest_liana/scopes_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def invalidate_scope_cache
1212
ForestLiana::ScopeManager.invalidate_scope_cache(rendering_id)
1313
return render serializer: nil, json: { status: 200 }, status: :ok
1414
rescue => error
15+
FOREST_REPORTER.report error
1516
FOREST_LOGGER.error "Error during scope cache invalidation: #{error.message}"
1617
render serializer: nil, json: {status: 500 }, status: :internal_server_error
1718
end

app/controllers/forest_liana/smart_actions_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def get_smart_action_request
1212
begin
1313
params[:data][:attributes]
1414
rescue => error
15+
FOREST_REPORTER.report error
1516
FOREST_LOGGER.error "Smart Action execution error: #{error}"
1617
{}
1718
end
@@ -47,6 +48,7 @@ def ensure_record_ids_in_scope
4748
# target records are out of scope
4849
render serializer: nil, json: { error: 'Smart Action: target record not found' }, status: :bad_request
4950
rescue => error
51+
FOREST_REPORTER.report error
5052
FOREST_LOGGER.error "Smart Action: #{error}\n#{format_stacktrace(error)}"
5153
render serializer: nil, json: { error: 'Smart Action: failed to evaluate permissions' }, status: :internal_server_error
5254
end
@@ -70,6 +72,7 @@ def check_permission_for_smart_route
7072
render serializer: nil, json: { status: 400 }, status: :bad_request
7173
end
7274
rescue => error
75+
FOREST_REPORTER.report error
7376
FOREST_LOGGER.error "Smart Action execution error: #{error}"
7477
render serializer: nil, json: { status: 400 }, status: :bad_request
7578
end
@@ -85,6 +88,7 @@ def find_resource(collection_name)
8588
end
8689
resource
8790
rescue => error
91+
FOREST_REPORTER.report error
8892
FOREST_LOGGER.error "Find Collection error: #{error}\n#{format_stacktrace(error)}"
8993
render serializer: nil, json: { status: 404 }, status: :not_found
9094
end

app/controllers/forest_liana/stats_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def get_with_live_query
6060
render json: { errors: [{ status: 422, detail: error.message }] },
6161
status: :unprocessable_entity, serializer: nil
6262
rescue => error
63+
FOREST_REPORTER.report error
6364
FOREST_LOGGER.error "Live Query error: #{error.message}"
6465
render json: { errors: [{ status: 422, detail: error.message }] },
6566
status: :unprocessable_entity, serializer: nil
@@ -110,6 +111,7 @@ def check_permission(permission_name)
110111

111112
return head :forbidden unless checker.is_authorized?
112113
rescue => error
114+
FOREST_REPORTER.report error
113115
FOREST_LOGGER.error "Stats execution error: #{error}"
114116
render serializer: nil, json: { status: 400 }, status: :bad_request
115117
end

app/services/forest_liana/intercom_attributes_getter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def perform
1818
@record = user
1919
rescue Intercom::ResourceNotFound
2020
rescue Intercom::UnexpectedError => exception
21+
FOREST_REPORTER.report exception
2122
FOREST_LOGGER.error "Cannot retrieve the Intercom attributes: #{exception.message}"
2223
end
2324
end

app/services/forest_liana/intercom_conversation_getter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def perform
1414
rescue Intercom::ResourceNotFound
1515
@record = nil
1616
rescue Intercom::UnexpectedError => exception
17+
FOREST_REPORTER.report exception
1718
FOREST_LOGGER.error "Cannot retrieve the Intercom conversation: #{exception.message}"
1819
@record = nil
1920
end

0 commit comments

Comments
 (0)