/// <summary>
        /// Initializes a new instance of the <see cref="ApolloServerErrorMessage" /> class.
        /// </summary>
        /// <param name="message">The message to put into the generated error.</param>
        /// <param name="code">The custom code to apply to the error message.</param>
        /// <param name="severity">The severity of the error message being generated.</param>
        /// <param name="lastMessageId">The id of the  message received which caused this error. The id will be returned
        /// as a meta data item for reference to the client.</param>
        /// <param name="lastMessageType">The type of the  message received which caused this error. The type will be returned
        /// as a meta data item for reference to the client.</param>
        /// <param name="exception">An internal exception that was thrown that should be carried with this message.</param>
        /// <param name="clientProvidedId">The client provided identifier of the failed operation.</param>
        public ApolloServerErrorMessage(
            string message,
            string code = Constants.ErrorCodes.DEFAULT,
            GraphMessageSeverity severity     = GraphMessageSeverity.Critical,
            string lastMessageId              = null,
            ApolloMessageType?lastMessageType = null,
            Exception exception     = null,
            string clientProvidedId = null)
            : base(ApolloMessageType.ERROR)
        {
            this.Id      = clientProvidedId;
            this.Payload = new GraphExecutionMessage(severity, message, code, SourceOrigin.None, exception);

            if (!string.IsNullOrWhiteSpace(lastMessageId))
            {
                this.Payload.MetaData.Add(ApolloConstants.Messaging.LAST_RECEIVED_MESSAGE_ID, lastMessageId);
            }

            if (lastMessageType.HasValue)
            {
                this.Payload.MetaData.Add(
                    ApolloConstants.Messaging.LAST_RECEIVED_MESSAGE_TYPE,
                    ApolloMessageTypeExtensions.Serialize(lastMessageType.Value));
            }
        }
예제 #2
0
        /// <summary>
        /// Returns an error indicating that an issue occured.
        /// </summary>
        /// <param name="severity">The severity of the message.</param>
        /// <param name="message">The human-friendly error message to assign ot the reported error in the graph result.</param>
        /// <param name="code">The error code to assign to the reported error in the graph result.</param>
        /// <param name="exception">An optional exception to be published if the query is configured to allow exposing exceptions.</param>
        /// <returns>IGraphActionResult.</returns>
        protected virtual IGraphActionResult Error(
            GraphMessageSeverity severity,
            string message,
            string code         = null,
            Exception exception = null)
        {
            var errorMessage = new GraphExecutionMessage(severity, message, code, exception: exception);

            return(this.Error(errorMessage));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultResponseWriter{TSchema}" /> class.
 /// </summary>
 /// <param name="schema">The schema from which repsonse settings should be drawn.</param>
 public DefaultResponseWriter(TSchema schema)
     : base(schema)
 {
     Validation.ThrowIfNull(schema, nameof(schema));
     _minSeverityLevel = schema.Configuration.ResponseOptions.MessageSeverityLevel;
     _writerOptions    = new JsonWriterOptions()
     {
         Indented = schema.Configuration.ResponseOptions.IndentDocument,
     };
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultResponseWriter{TSchema}" /> class.
        /// </summary>
        /// <param name="schema">The schema from which repsonse settings should be drawn.</param>
        public DefaultResponseWriter(TSchema schema)
        {
            Validation.ThrowIfNull(schema, nameof(schema));
            _minSeverityLevel = schema.Configuration.ResponseOptions.MessageSeverityLevel;
            _timeLocalizer    = schema.Configuration.ResponseOptions.TimeStampLocalizer;
            _nameFormatter    = schema.Configuration.DeclarationOptions.GraphNamingFormatter;
            _writerOptions    = new JsonWriterOptions()
            {
                Indented = schema.Configuration.ResponseOptions.IndentDocument,
            };

            _serializerSettings         = new JsonSerializerOptions();
            _serializerSettings.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphExecutionMessage" /> class.
 /// </summary>
 /// <param name="severity">The severity level of this message.</param>
 /// <param name="message">The message text body.</param>
 /// <param name="code">The code assigned to this message, if any.</param>
 /// <param name="origin">The origin in the source text where this message was generated.</param>
 /// <param name="exception">The underlying exception that was thrown by the runtime, if any.</param>
 public GraphExecutionMessage(
     GraphMessageSeverity severity,
     string message,
     string code         = null,
     SourceOrigin origin = null,
     Exception exception = null)
 {
     this.Origin    = origin ?? SourceOrigin.None;
     this.Code      = code?.Trim() ?? "-unknown-";
     this.Message   = message?.Trim();
     this.Severity  = severity;
     this.Exception = exception;
     this.TimeStamp = DateTimeOffset.UtcNow;
     this.MetaData  = new Dictionary <string, object>();
 }
        /// <summary>
        /// Adds the message to the collection.
        /// </summary>
        /// <param name="severity">The severity of this new message.</param>
        /// <param name="message">The body text for this new message.</param>
        /// <param name="errorCode">An optional error code to apply to the message..</param>
        /// <param name="origin">The origin in the source text, if any, that this message relates to.</param>
        /// <param name="exceptionThrown">An exception that may have been thrown and caused this message to be created.</param>
        /// <returns>IGraphExecutionMessage.</returns>
        public IGraphMessage Add(
            GraphMessageSeverity severity,
            string message,
            string errorCode          = "",
            SourceOrigin origin       = null,
            Exception exceptionThrown = null)
        {
            var graphMessage = new GraphExecutionMessage(
                severity,
                message,
                errorCode,
                origin,
                exceptionThrown);

            return(this.Add(graphMessage));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApolloServerErrorMessage" /> class.
 /// </summary>
 /// <param name="message">The message to put into the generated error.</param>
 /// <param name="code">The custom code to apply to the error message.</param>
 /// <param name="severity">The severity of the error message being generated.</param>
 /// <param name="lastMessage">The last message received by the server, generally the message
 /// that resulted in this error being generated.</param>
 /// <param name="exception">An internal exception that was thrown that should be carried with this message.</param>
 /// <param name="clientProvidedId">The client provided identifier of the failed operation.</param>
 public ApolloServerErrorMessage(
     string message,
     string code = Constants.ErrorCodes.DEFAULT,
     GraphMessageSeverity severity = GraphMessageSeverity.Critical,
     ApolloMessage lastMessage     = null,
     Exception exception           = null,
     string clientProvidedId       = null)
     : this(
         message,
         code,
         severity,
         lastMessage?.Id,
         lastMessage?.Type,
         exception,
         clientProvidedId)
 {
 }
예제 #8
0
 /// <summary>
 /// Determines whether the specified severity is critical.
 /// </summary>
 /// <param name="severity">The severity to inspect.</param>
 /// <returns><c>true</c> if the specified severity is critical; otherwise, <c>false</c>.</returns>
 public static bool IsCritical(this GraphMessageSeverity severity)
 {
     return(severity >= GraphMessageSeverity.Critical);
 }