/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Kafka.Client
{
///
/// A wrapping of an error code returned from Kafka.
///
public class KafkaException : Exception
{
///
/// No error occurred.
///
public const int NoError = 0;
///
/// The offset requested was out of range.
///
public const int OffsetOutOfRangeCode = 1;
///
/// The message was invalid.
///
public const int InvalidMessageCode = 2;
///
/// The wrong partition.
///
public const int WrongPartitionCode = 3;
///
/// Invalid message size.
///
public const int InvalidRetchSizeCode = 4;
///
/// Initializes a new instance of the KafkaException class.
///
/// The error code generated by a request to Kafka.
public KafkaException(int errorCode) : base(GetMessage(errorCode))
{
ErrorCode = errorCode;
}
///
/// Gets the error code that was sent from Kafka.
///
public int ErrorCode { get; private set; }
///
/// Gets the message for the exception based on the Kafka error code.
///
/// The error code from Kafka.
/// A string message representation
private static string GetMessage(int errorCode)
{
if (errorCode == OffsetOutOfRangeCode)
{
return "Offset out of range";
}
else if (errorCode == InvalidMessageCode)
{
return "Invalid message";
}
else if (errorCode == WrongPartitionCode)
{
return "Wrong partition";
}
else if (errorCode == InvalidRetchSizeCode)
{
return "Invalid message size";
}
else
{
return "Unknown error";
}
}
}
}