Skip to content

Commit

Permalink
[BUGFIX] Fix exit codes in AbstractClientRequestCommand
Browse files Browse the repository at this point in the history
AbstractClientRequestCommand just returns the response form
RequestService by casting it to an integer. However, the return
value must be negated since the RequestService returns true (1)
on success and false (0) on failure.

Exit code 1 is now also returned if the API responded with an error.
  • Loading branch information
o-ba committed Dec 3, 2020
1 parent 3632472 commit 774e005
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Command/AbstractClientRequestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->setRaw($input->getOption('raw') !== false)
->setDefaultAuthMethod($this->defaultAuthMethod);

return (int)(new RequestService(
// RequestService returns a boolean for whether the request was successful or not.
// Since we have to return an exit code, this must be negated and casted to return
// 0 on success and 1 on failure.
return (int)!(new RequestService(
$requestConfiguration,
new ConsoleWriter($io, $this->getMessages(), $this->resultFormat)
))->run();
Expand Down
1 change: 1 addition & 0 deletions src/Service/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function run(): bool
$this->consoleWriter->writeFailure(
(string)($content['error_description'] ?? $content['message'] ?? 'Unknown (Status ' . $status . ')')
);
return false;
}
} catch (ExceptionInterface|\InvalidArgumentException $e) {
$this->consoleWriter->error('An error occurred: ' . $e->getMessage());
Expand Down

0 comments on commit 774e005

Please sign in to comment.