func()

in lambda/rapi/handler/invocationerror.go [38:102]


func (h *invocationErrorHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	appCtx := appctx.FromRequest(request)

	server := appctx.LoadResponseSender(appCtx)
	if server == nil {
		log.Panic("Invalid state, cannot access interop server")
	}

	runtime := h.registrationService.GetRuntime()
	if err := runtime.InvocationErrorResponse(); err != nil {
		log.Warn(err)
		rendering.RenderForbiddenWithTypeMsg(writer, request, rendering.ErrorTypeInvalidStateTransition, StateTransitionFailedForRuntimeMessageFormat,
			runtime.GetState().Name(), core.RuntimeInvocationErrorResponseStateName, err)
		return
	}

	errorType := fatalerror.GetValidRuntimeOrFunctionErrorType(h.getErrorType(request.Header))

	var errorCause json.RawMessage
	var errorBody []byte
	var contentType string
	var err error

	switch request.Header.Get(contentTypeHeader) {
	case errorWithCauseContentType:
		errorBody, errorCause, err = h.getErrorBodyForErrorCauseContentType(request)
		contentType = "application/json"
		if err != nil {
			contentType = "application/octet-stream"
		}
	default:
		errorBody, err = h.getErrorBody(request)
		errorCause = h.getValidatedErrorCause(request.Header)
		contentType = request.Header.Get(contentTypeHeader)
	}
	functionResponseMode := request.Header.Get(functionResponseModeHeader)

	if err != nil {
		log.WithError(err).Warn("Failed to parse error body")
	}

	headers := interop.InvokeResponseHeaders{
		ContentType:          contentType,
		FunctionResponseMode: functionResponseMode,
	}

	response := &interop.ErrorInvokeResponse{
		Headers:       headers,
		FunctionError: interop.FunctionError{Type: errorType},
		Payload:       errorBody,
	}

	if err := server.SendErrorResponse(chi.URLParam(request, "awsrequestid"), response); err != nil {
		rendering.RenderInteropError(writer, request, err)
		return
	}

	appctx.StoreInvokeErrorTraceData(appCtx, &interop.InvokeErrorTraceData{ErrorCause: errorCause})

	if err := runtime.ResponseSent(); err != nil {
		log.Panic(err)
	}

	rendering.RenderAccepted(writer, request)
}