Skip to content

Commit

Permalink
better error handling for Import.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Mar 5, 2024
1 parent 6cfa0d0 commit 3620d2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/trailblazer/pro/editor/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module Trailblazer
module Pro
module Editor
class Import < Trailblazer::Activity::Railway
step Subprocess(Client::Connect), id: :connect
step Subprocess(Client::Connect), id: :connect,
Output(:failure) => End(:failure)
step :retrieve_document
fail :error_for_retrieve
step :store_document

def retrieve_document(ctx, session:, diagram_slug:, **)
Expand All @@ -25,6 +27,10 @@ def retrieve_document(ctx, session:, diagram_slug:, **)
def store_document(ctx, pro_json_document:, target_filename:, **)
File.write(target_filename, pro_json_document) > 0
end

def error_for_retrieve(ctx, response:, diagram_slug:, **)
ctx[:error_message] = %(Diagram #{diagram_slug.inspect} couldn't be retrieved. HTTP status: #{response.status})
end
end

end # Editor
Expand Down
11 changes: 11 additions & 0 deletions test/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ class ApiTest < Minitest::Spec

# TODO: use endpoint to run, and 404, 401 paths
assert_equal signal.inspect, %(#<Trailblazer::Activity::End semantic=:failure>)
assert_equal ctx[:error_message], %(Diagram "xxxfff" couldn't be retrieved. HTTP status: 401)

assert_equal File.exist?("test/imported_json/xxxfff.json"), false
end

it "401 unauthorized because wrong token" do
Trailblazer::Pro.initialize!(api_key: "XXX api_key", trailblazer_pro_host: trailblazer_pro_host)

signal, (ctx, _) = Trailblazer::Developer.wtf?(Trailblazer::Pro::Editor::Import, [{
diagram_slug: "b0f945",
target_filename: "test/imported_json/b0f945.json",
session: Trailblazer::Pro::Session.session
},
{}
])

assert_equal ctx[:error_message], %(Custom token couldn't be retrieved. HTTP status: 401)
end
end

0 comments on commit 3620d2f

Please sign in to comment.