@@ -1,5 +1,6 @@ |
||
| 1 | 1 |
class AgentsController < ApplicationController |
| 2 | 2 |
include DotHelper |
| 3 |
+ include ActionView::Helpers::TextHelper |
|
| 3 | 4 |
include SortableTable |
| 4 | 5 |
|
| 5 | 6 |
def index |
@@ -44,13 +45,25 @@ class AgentsController < ApplicationController |
||
| 44 | 45 |
end |
| 45 | 46 |
agent = Agent.build_for_type(type, current_user, attrs) |
| 46 | 47 |
agent.name ||= '(Untitled)' |
| 47 |
- results = agent.dry_run! |
|
| 48 | 48 |
|
| 49 |
- render json: {
|
|
| 49 |
+ if agent.valid? |
|
| 50 |
+ results = agent.dry_run! |
|
| 51 |
+ |
|
| 52 |
+ render json: {
|
|
| 50 | 53 |
log: results[:log], |
| 51 | 54 |
events: Utils.pretty_print(results[:events], false), |
| 52 | 55 |
memory: Utils.pretty_print(results[:memory] || {}, false),
|
| 53 |
- } |
|
| 56 |
+ } |
|
| 57 |
+ else |
|
| 58 |
+ render json: {
|
|
| 59 |
+ log: [ |
|
| 60 |
+ "#{pluralize(agent.errors.count, "error")} prohibited this Agent from being saved:",
|
|
| 61 |
+ *agent.errors.full_messages |
|
| 62 |
+ ].join("\n- "),
|
|
| 63 |
+ events: '', |
|
| 64 |
+ memory: '', |
|
| 65 |
+ } |
|
| 66 |
+ end |
|
| 54 | 67 |
end |
| 55 | 68 |
|
| 56 | 69 |
def type_details |