Skip to content

Commit

Permalink
issue-11: add back util function is_failed_response
Browse files Browse the repository at this point in the history
  • Loading branch information
IslaL committed Apr 22, 2024
1 parent 8f94aab commit 2a8c3dc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions onc/+util/is_failed_response.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function isFailed = is_failed_response(response, status)
%% Checks if a server response describes a failure
%
% * response: (struct) Response as returned by do_request()
% - status: (double) http status code
%
% Returns: (Logical) true when the response is a failure
isFailed = false;

% Fail if HTTP status code is not a 2xx
if exist('status', 'var')
if status < 200 || status > 226
isFailed = true;
return
end
end

% Fail if the response is an error description
if isfield(response, "errors")
names = fieldnames(response.errors(1));
isFailed = ismember("errorCode", names) && ismember("errorMessage", names);
end
end

0 comments on commit 2a8c3dc

Please sign in to comment.