Skip to content

Format 4xx/5xx status codes and return error code #2

Closed
david-pershouse wants to merge 5 commits intobinarylane:mainfrom
david-pershouse:feature/error-handling
Closed

Format 4xx/5xx status codes and return error code #2
david-pershouse wants to merge 5 commits intobinarylane:mainfrom
david-pershouse:feature/error-handling

Conversation

@david-pershouse
Copy link
Copy Markdown
Contributor

@david-pershouse david-pershouse commented Jan 25, 2023

When a request receives a response with 4xx or 5xx status codes, it is now treated as an error and bl will return error level of -1.
This MR also applies custom formatting to the ProblemDetails and ValidationProblemDetails objects that are common in the error response.

ProblemDetails (usually with 5xx errors) is just rendered as ERROR: {title} - {detail} where detail is optional

eg for a 404

PS C:\dev\vps\python-blcli> poetry run bl server action resize 33
ERROR:  Server not found.

ValidationProblemDetails (4xx validation errors) is similar to problem details, but includes the errors property as a table

PS C:\dev\python-blcli> bl server create --size blah --region blah2  --image blkah
Error: One or more validation errors occurred.
┌────────┬─────────────────────────────┐
│ field  │ errors                      │
├────────┼─────────────────────────────┤
│ size   │ size not found.             │
│ image  │ Operating system not found. │
│ region │ Facility not found.         │
└────────┴─────────────────────────────┘

Add error option to printer and refactor base printer to be in charge of out outputting to stderr/out
exit with -1 for all error status codes
supress action warning for error responses
@david-pershouse
Copy link
Copy Markdown
Contributor Author

This has now been changed to obey the --output argument. This required some refactoring of the printer classes. The main change is the introduction of an error() method to the printers which is like print but outputs to stderr. The error function renders any tables including their headings and with all fields (as it is assumed the these options were specific to success response types).

To avoid passing output file down to each subclass of printer, the printer sub-classes now just return string.

I tried to use the built in "title" property of terminaltables, but could not get it to render correctly (or at all) in windows, so this PR just prints a single line title.

@david-pershouse
Copy link
Copy Markdown
Contributor Author

The bulk of this was addressed in #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant