Skip to content

Commit e71c9e1

Browse files
committed
convert params to string, better exception log
- Path parameters are sub strings when they are parsed from HTTP request. Method parameters would however unlikely to be typed as substrings (`String`/`AbstractString` is more likely if they are at all). We now convert parsed path parameters to `String` before invoking methods. - Use `showerror` to log exceptions for more readable messages
1 parent e5dc0ad commit e71c9e1

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/APIResponder.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function call_api(api::APISpec, conn::APIResponder, args, data::Dict{Symbol,Any}
9797
result = dynamic_invoke(conn, api.fn, args...; data...)
9898
respond(conn, Nullable(api), :success, result)
9999
catch ex
100-
err("api_exception: $ex")
100+
logerr("api_exception: ", ex)
101101
respond(conn, Nullable(api), :api_exception)
102102
end
103103
end
@@ -163,7 +163,7 @@ function process(conn::APIResponder; async::Bool=false)
163163
try
164164
call_api(conn.endpoints[command], conn, args(conn.format, msg), data(conn.format, msg))
165165
catch ex
166-
err("exception ", ex)
166+
logerr("exception ", ex)
167167
respond(conn, Nullable(conn.endpoints[command]), :invalid_data)
168168
end
169169
end
@@ -227,3 +227,10 @@ function process()
227227
eval(parse(cmd))
228228
nothing
229229
end
230+
231+
function logerr(msg, ex)
232+
iob = IOBuffer()
233+
write(iob, msg)
234+
showerror(iob, ex)
235+
err(String(take!(iob)))
236+
end

src/http_rpc_server.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function http_handler{T,F}(apis::Channel{APIInvoker{T,F}}, preproc::Function, re
158158
else
159159
data_dict = parsepostdata(req, data_dict, multipart_boundary)
160160
end
161-
args = split(path, '/', keep=false)
161+
args = map(String, split(path, '/', keep=false))
162162

163163
if isempty(args) || !isvalidcmd(args[1])
164164
res = Response(404)

test/clnt.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ function run_clnt(fmt, tport)
6060
t = toc();
6161
println("time for $NCALLS calls to testbinary: $t secs @ $(t/NCALLS) per call")
6262

63-
#Test Array invocation
64-
63+
# Test Array invocation
6564
resp = apicall(apiclnt, "testArray", Float64[1.0 2.0; 3.0 4.0])
6665
@test fnresponse(apiclnt.format, resp) == 12
6766

67+
# Test unknown function call
68+
resp = apicall(apiclnt, "testNoSuchMethod", Float64[1.0 2.0; 3.0 4.0])
69+
@test resp["code"] == 404
70+
resp = apicall(apiclnt, "testArray", "no such argument")
71+
@test resp["code"] == 500
72+
6873
close(ctx)
6974
close(tport)
7075
end

0 commit comments

Comments
 (0)