| 86 | |
| 87 | @classmethod |
| 88 | def jsonify_result(cls, result, extra=None, **kwargs): |
| 89 | data = result.to_dict(serializer=cls) |
| 90 | if extra is not None: |
| 91 | data.update(extra) |
| 92 | # Sometimes part of the result might be missing because of some |
| 93 | # inconsistency (eg: a failed re-indexing). We try to spot those |
| 94 | # inconsistencies. |
| 95 | total = data.get("total", 0) |
| 96 | limit = data.get("limit", 0) |
| 97 | offset = data.get("offset", 0) |
| 98 | if total > 0 and not data.get("results"): |
| 99 | if not (limit == 0 or offset >= total): |
| 100 | log.exception(f"Expected more results in the response: {data}") |
| 101 | data = { |
| 102 | "status": "error", |
| 103 | "message": gettext( |
| 104 | "We found %(total)d results, but could not load them due " |
| 105 | "to a technical problem. Please check back later and if " |
| 106 | "the problem persists contact an Aleph administrator", |
| 107 | total=total, |
| 108 | ), |
| 109 | } |
| 110 | return jsonify(data, status=500) |
| 111 | return jsonify(data, **kwargs) |
| 112 | |
| 113 | |
| 114 | class RoleSerializer(Serializer): |