status.data_updated = await _get_database_date(conn)
status.database_version = await _get_database_version(conn)
except asyncpg.PostgresError:
- return StatusResult(700, 'No database')
+ return StatusResult(700, 'Database connection failed')
return status
@create.format_func(StatusResult, 'text')
def _format_status_text(result: StatusResult) -> str:
- return result.message
+ if result.status:
+ return f"ERROR: {result.message}"
+
+ return 'OK'
@create.format_func(StatusResult, 'json')
result = await self.api.status()
self.format_response(req, resp, result)
+ if result.status and req.context.format == 'text':
+ resp.status = 500
def get_application(project_dir: Path,
async def status(request: sanic.Request) -> sanic.HTTPResponse:
""" Implementation of status endpoint.
"""
- return api_response(request,await request.app.ctx.api.status())
+ result = await request.app.ctx.api.status()
+ response = api_response(request, result)
+
+ if request.ctx.format == 'text' and result.status:
+ response.status = 500
+
+ return response
def get_application(project_dir: Path,
"""
parse_format(request, StatusResult, 'text')
result = await request.app.state.API.status()
- return format_response(request, result)
+ response = format_response(request, result)
+
+ if request.state.format == 'text' and result.status:
+ response.status_code = 500
+
+ return response
V1_ROUTES = [
result = api.status()
assert result.status == 700
- assert result.message == 'No database'
+ assert result.message == 'Database connection failed'
assert result.software_version == version_str()
assert result.database_version is None
assert result.data_updated is None
def test_format_text(self):
- assert self.formatter.format(StatusResult(0, 'message here'), 'text') == 'message here'
+ assert self.formatter.format(StatusResult(0, 'message here'), 'text') == 'OK'
+
+
+ def test_format_text(self):
+ assert self.formatter.format(StatusResult(500, 'message here'), 'text') == 'ERROR: message here'
def test_format_json_minimal(self):