def handle_standard_error(error: BasicError) -> Response: """ Adapts the visualization of an standard error so it complies with the schema, Hydra. """ response = jsonify(error.to_dict()) header_name, header_value = get_header_link(type(error).__name__) response.headers[header_name] = header_value response.status_code = error.status_code return response
def set_response_headers_and_cache(resource: str, _, payload: Response): """ Sets JSON Header link referring to @type """ if (payload._status_code == 200 or payload._status_code == 304) and resource is not None: data = json.loads(payload.data.decode(payload.charset)) resource_type = resource try: resource_type = data['@type'] except KeyError: if payload._status_code == 304: payload.cache_control.max_age = current_app.config['ITEM_CACHE'] else: # If we are here it means it is an item endpoint, not a list (resource) endpoint payload.cache_control.max_age = current_app.config['ITEM_CACHE'] payload.headers._list.append(get_header_link(resource_type))
def set_response_headers_and_cache(resource: str, _, payload: Response): """ Sets JSON Header link referring to @type """ if (payload._status_code == 200 or payload._status_code == 304) and resource is not None: data = json.loads(payload.data.decode(payload.charset)) resource_type = resource try: resource_type = data['@type'] except KeyError: if payload._status_code == 304: payload.cache_control.max_age = current_app.config[ 'ITEM_CACHE'] else: # If we are here it means it is an item endpoint, not a list (resource) endpoint payload.cache_control.max_age = current_app.config['ITEM_CACHE'] payload.headers._list.append(get_header_link(resource_type))