Method: Gruf::Error#attach_to_call

Defined in:
lib/gruf/error.rb

#attach_to_call(active_call) ⇒ Error

Update the trailing metadata on the given gRPC call, including the error payload if configured to do so.

Parameters:

  • active_call (GRPC::ActiveCall)

    The marshalled gRPC call

Returns:

  • (Error)

    Return the error itself after updating metadata on the given gRPC call. In the case of a metadata overflow error, we replace the current error with a new one that won’t cause a low-level http2 error.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/gruf/error.rb', line 151

def attach_to_call(active_call)
  [Gruf..to_sym] = serialize if Gruf.
  return self if .empty? || !active_call || !active_call.respond_to?(:output_metadata)

  # Check if we've overflown the maximum size of output metadata. If so,
  # log a warning and replace the metadata with something smaller to avoid
  # resource exhausted errors.
  if .inspect.size > MAX_METADATA_SIZE
    code = METADATA_SIZE_EXCEEDED_CODE
    msg = METADATA_SIZE_EXCEEDED_MSG
    logger.warn "#{code}: #{msg} Original error: #{to_h.inspect}"
    err = Gruf::Error.new(code: :internal, app_code: code, message: msg)
    return err.attach_to_call(active_call)
  end

  active_call..update()
  self
end