Skip to content

Commit 6fd4f68

Browse files
committed
fix: improve errors on backend errors
1 parent 8895f99 commit 6fd4f68

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/datasets.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ function upload_dataset end
695695
# Any other 404 or other non-200 response indicates a backend failure
696696
_throw_invalidresponse(r)
697697
end
698+
_check_internal_error(r; var="POST /user/datasets/{name}/versions")
698699
upload_config = _check_dataset_upload_config(r, dtype; newly_created_dataset)
699700
# Upload the actual data
700701
try

src/projects.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ function upload_project_dataset(
241241
# Other response codes indicate a backend failure
242242
_throw_invalidresponse(r)
243243
end
244+
_check_internal_error(r; var="POST /user/datasets/{name}/versions")
244245
# ...
245246
upload_config = _check_dataset_upload_config(r, dtype; newly_created_dataset=false)
246247
# Upload the actual data

src/utils.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,31 @@ function _json_check_success(json::Dict; var::AbstractString)
361361
return nothing
362362
end
363363

364+
# Check that the API response is not a legacy 200 internal error, where
365+
# we return
366+
#
367+
# {"success": false, "interal_error": true, "message": "..."}
368+
#
369+
# on internal errors. If it detects that this is an internal error, it throws
370+
# a JuliaHubError. Returns `nothing` otherwise.
371+
function _check_internal_error(r::_RESTResponse; var::AbstractString)
372+
if !(r.status == 200)
373+
return nothing
374+
end
375+
success = _get_json_or(r.json, "success", Any, nothing)
376+
internal_error = _get_json_or(r.json, "internal_error", Any, nothing)
377+
if (success === false) && (internal_error === true)
378+
e = JuliaHubError(
379+
"""
380+
Internal Server Error 200 response from JuliaHub ($var):
381+
JSON: $(sprint(show, MIME("text/plain"), r.json))
382+
""",
383+
)
384+
throw(e)
385+
end
386+
return nothing
387+
end
388+
364389
# Performs the print of f(::IO), but prepends `indent` spaces in front of
365390
# each line, to make it indented.
366391
function _print_indented(io::IO, f; indent::Integer)

0 commit comments

Comments
 (0)