-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue-11: add back util function is_failed_response
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |