Skip to content

Commit

Permalink
Update for Retry.jl change.
Browse files Browse the repository at this point in the history
JuliaWeb/Retry.jl@6c565a3

JuliaLang/julia#19979 (comment)

Retry.jl no longer allows @ignore if conditions to throw errors.

To support this:
 - Dynamic generation of exception types is removed from AWSException.jl
   (All exceptions are now type AWSException with fields: code, message,
info and cause.
 - Exception handling conditions have added type checks.
  • Loading branch information
samoconnor committed Nov 21, 2017
1 parent 3741d8c commit 471dff4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
7 changes: 4 additions & 3 deletions src/AWSCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function do_request(r::AWSRequest)
catch e

# Handle HTTP Redirect...
@retry if http_status(e) in [301, 302, 307] &&
@retry if isa(e, HTTP.StatusError) && http_status(e) in [301, 302, 307] &&
haskey(headers(e), "Location")
r[:url] = headers(e)["Location"]
end
Expand All @@ -430,10 +430,11 @@ function do_request(r::AWSRequest)
end

# Handle expired signature...
@retry if ismatch(r"Signature expired", e.message) end
@retry if :message in fieldnames(e) &&
ismatch(r"Signature expired", e.message) end

# Handle ExpiredToken...
@retry if typeof(e) == ExpiredToken
@retry if ecode(e) == "ExpiredToken"
r[:creds].token = "ExpiredToken"
end
end
Expand Down
17 changes: 7 additions & 10 deletions src/AWSException.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import JSON: json

export AWSException

abstract type AWSException <: Exception end
struct AWSException <: Exception
code
message
info
cause
end

function Base.show(io::IO,e::AWSException)
println(io, string(e.code,
Expand Down Expand Up @@ -50,15 +55,7 @@ function AWSException(e::HTTP.StatusError)
code = get(info, "Code", code)
message = get(info, "Message", message)

# Create specialised exception object based on "code"...
etype = Symbol(code)
@repeat 2 try
e = eval(:($etype($code, $message, $info, $e)))
catch x
@retry if isa(x, UndefVarError)
eval(:(type $etype <: AWSException code; message; info; cause end))
end
end
AWSException(code, message, info, e)
end


Expand Down
16 changes: 4 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ try
@test false
catch e
println(e)
@test isa(e, AWSCore.InvalidAction)
@test ecode(e) == "InvalidAction"
end

try
Expand All @@ -45,11 +45,7 @@ try
@test false
catch e
println(e)
if isdefined(AWSCore, :AccessDenied)
@test isa(e, AWSCore.AccessDenied)
else
@test isa(e, AWSCore.NoSuchEntity)
end
@test ecode(e) in ["AccessDenied", "NoSuchEntity"]
end

try
Expand All @@ -58,7 +54,7 @@ try
@test false
catch e
println(e)
@test isa(e, AWSCore.ValidationError)
@test ecode(e) == "ValidationError"
end

try
Expand All @@ -67,11 +63,7 @@ try
@test false
catch e
println(e)
if isdefined(AWSCore, :AccessDenied)
@test isa(e, AWSCore.AccessDenied)
else
@test isa(e, AWSCore.EntityAlreadyExists)
end
@test ecode(e) in ["AccessDenied", "EntityAlreadyExists"]
end


Expand Down

0 comments on commit 471dff4

Please sign in to comment.