| class HiddenAPIKey(fields.Raw): | class HiddenAPIKey(fields.Raw): | ||||
| def output(self, key, obj): | |||||
| def output(self, key, obj, **kwargs): | |||||
| api_key = obj.api_key | api_key = obj.api_key | ||||
| # If the length of the api_key is less than 8 characters, show the first and last characters | # If the length of the api_key is less than 8 characters, show the first and last characters | ||||
| if len(api_key) <= 8: | if len(api_key) <= 8: |
| data = getattr(e, "data", default_data) | data = getattr(e, "data", default_data) | ||||
| error_cls_name = type(e).__name__ | |||||
| if error_cls_name in self.errors: | |||||
| custom_data = self.errors.get(error_cls_name, {}) | |||||
| custom_data = custom_data.copy() | |||||
| status_code = custom_data.get("status", 500) | |||||
| if "message" in custom_data: | |||||
| custom_data["message"] = custom_data["message"].format( | |||||
| message=str(e.description if hasattr(e, "description") else e) | |||||
| ) | |||||
| data.update(custom_data) | |||||
| # record the exception in the logs when we have a server error of status code: 500 | # record the exception in the logs when we have a server error of status code: 500 | ||||
| if status_code and status_code >= 500: | if status_code and status_code >= 500: | ||||
| exc_info: Any = sys.exc_info() | exc_info: Any = sys.exc_info() |
| class AppIconUrlField(fields.Raw): | class AppIconUrlField(fields.Raw): | ||||
| def output(self, key, obj): | |||||
| def output(self, key, obj, **kwargs): | |||||
| if obj is None: | if obj is None: | ||||
| return None | return None | ||||
| class AvatarUrlField(fields.Raw): | class AvatarUrlField(fields.Raw): | ||||
| def output(self, key, obj): | |||||
| def output(self, key, obj, **kwargs): | |||||
| if obj is None: | if obj is None: | ||||
| return None | return None | ||||