func()

in lambda/rapi/handler/invocationerror.go [32:91]


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

	server := appctx.LoadInteropServer(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 := h.getErrorType(request.Header)

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

	switch request.Header.Get("Content-Type") {
	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("Content-Type")
	}

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

	response := &interop.ErrorResponse{
		ErrorType:   errorType,
		Payload:     errorBody,
		ErrorCause:  errorCause,
		ContentType: contentType,
	}

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

	appctx.StoreErrorResponse(appCtx, response)

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

	rendering.RenderAccepted(writer, request)
}