 
   set_error : (code, desc = null, fields = null) ->
     @oo.status = make_status_obj code, desc, fields
-    log.warn "set_error #{code} #{desc}" unless code is sc.OK
-    new Error code
 
   #-----------------------------------------
 

  #-----------------------------------------
  
  send_res_json : (cb) ->
    @format_res()
    respond { obj : @oo, code : @http_out_code, encoding : @out_encoding, @res }
    @response_sent_yet = true
    cb()

  #-----------------------------------------

  format_res : ->
    if @oo.status?.code
      # noop
    else if not @is_input_ok()
      @set_error sc.INPUT_ERROR, "Error in JSON input", @_error_in_field
    else
      @set_ok()
   
  #==============================================
  
  handle : (cb) ->

      code = err.sc or sc.GENERIC_ERROR
      @set_error code, err.message 
      @http_out_code = c if (c = err.http_code)?
      log.warn "Error #{code}: #{err.message}"

  #------
  
