Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#take care of includes
if response_obj.include_relationships != None: self.include_relationships = response_obj.include_relationships
included = None
janus_logger.info("Should map included: " + str(self.include_relationships))
if self.include_relationships:
included = self.__load_included(data,self.nest_in_responses)
#is there custome meta?
if response_obj.meta != None:
if self.meta == None:
self.meta = response_obj.meta
else:
self.meta.update(response_obj.meta)
message = JsonApiMessage(data=data,included=included,meta=self.meta,do_nesting=self.nest_in_responses).to_json() #render json response
#caching
if self.cached_set_hook != None and loaded_from_cache == False:
janus_logger.debug("Caching message")
self.cached_set_hook(response_obj,message)
if self.before_send_hook != None: #fire before send hook
self.before_send_hook(self.success_status,message,response_obj)
return message
except Exception as e:
err_msg = ErrorMessage.from_exception(e)
tb = traceback.format_exc()
if self.include_traceback_in_errors:
if err_msg.meta == None: err_msg.meta = {}
if self.before_send_hook != None: #fire before send hook
self.before_send_hook(self.success_status,message,response_obj)
return message
except Exception as e:
err_msg = ErrorMessage.from_exception(e)
tb = traceback.format_exc()
if self.include_traceback_in_errors:
if err_msg.meta == None: err_msg.meta = {}
err_msg.traceback = tb
if self.error_hook != None:
self.error_hook(int(err_msg.status),err_msg,tb)
message = JsonApiMessage(errors=err_msg,meta=self.meta).to_json()
janus_logger.error("Traceback: " + tb)
return message
if self.before_send_hook != None: #fire before send hook
self.before_send_hook(self.success_status,message,None)
return message
except Exception as e:
err_msg = ErrorMessage.from_exception(e)
tb = traceback.format_exc()
if self.include_traceback_in_errors:
if err_msg.meta == None: err_msg.meta = {}
err_msg.traceback = tb
if self.error_hook != None:
self.error_hook(int(err_msg.status),err_msg,tb)
message = JsonApiMessage(errors=err_msg).to_json()
return message
return None
else:
if isinstance(messages, (list, tuple)) == False:
raise Exception('Methods using the "describe" decorator have to return a list of subclasses of DataMessage to describe.')
msg_descriptions = []
for msg in messages:
if issubclass(msg,DataMessage) == False:
raise Exception('All returned classes in the returned list have to be a subclass of DataMessage.')
msg_descriptions.append(msg().describe())
meta = {'message-types':msg_descriptions}
message = JsonApiMessage(meta=meta).to_json() #render json response
if self.before_send_hook != None: #fire before send hook
self.before_send_hook(self.success_status,message,None)
return message
except Exception as e:
err_msg = ErrorMessage.from_exception(e)
tb = traceback.format_exc()
if self.include_traceback_in_errors:
if err_msg.meta == None: err_msg.meta = {}
err_msg.traceback = tb
if self.error_hook != None:
self.error_hook(int(err_msg.status),err_msg,tb)