const require_errors = require('./errors-BtJEw2Z-.cjs');
const require_logging = require('./logging-CkAJKyq2.cjs');
const require_errors$1 = require('./errors-Bmqdg5Q6.cjs');

//#region src/internal/error-handling.ts
/**
* Type guard to identify user input validation errors.
*/
function isUserInputError(error) {
	return error instanceof require_errors.UserInputError;
}
/**
* Type guard to identify configuration errors.
*/
function isConfigurationError(error) {
	return error instanceof require_errors.ConfigurationError;
}
/**
* Type guard to identify API errors.
*/
function isApiError(error) {
	return error instanceof require_errors$1.ApiError;
}
/**
* Type guard to identify API client errors (4xx).
*/
function isApiClientError(error) {
	return error instanceof require_errors$1.ApiClientError;
}
/**
* Type guard to identify API server errors (5xx).
*/
function isApiServerError(error) {
	return error instanceof require_errors$1.ApiServerError;
}
/**
* Format an error for user display with markdown formatting.
* This is used by tool handlers to format errors for MCP responses.
*
* SECURITY: Only return trusted error messages to prevent prompt injection vulnerabilities.
* We trust: Sentry API errors, our own UserInputError/ConfigurationError messages, and system templates.
*/
async function formatErrorForUser(error) {
	if (isUserInputError(error)) return [
		"**Input Error**",
		"It looks like there was a problem with the input you provided.",
		error.message,
		`You may be able to resolve the issue by addressing the concern and trying again.`
	].join("\n\n");
	if (isConfigurationError(error)) return [
		"**Configuration Error**",
		"There appears to be a configuration issue with your setup.",
		error.message,
		`Please check your environment configuration and try again.`
	].join("\n\n");
	if (isApiClientError(error)) {
		const statusText = error.status ? `There was an HTTP ${error.status} error with your request to the Sentry API.` : "There was an error with your request.";
		return [
			"**Input Error**",
			statusText,
			error.toUserMessage(),
			`You may be able to resolve the issue by addressing the concern and trying again.`
		].join("\n\n");
	}
	if (isApiServerError(error)) {
		const eventId$1 = require_logging.logIssue(error);
		const statusText = error.status ? `There was an HTTP ${error.status} server error with the Sentry API.` : "There was a server error.";
		return [
			"**Error**",
			statusText,
			`${error.message}`,
			`**Event ID**: ${eventId$1}`,
			`Please contact support with this Event ID if the problem persists.`
		].join("\n\n");
	}
	if (isApiError(error)) {
		const statusText = error.status ? `There was an HTTP ${error.status} error with your request to the Sentry API.` : "There was an error with your request.";
		return [
			"**Error**",
			statusText,
			`${error.message}`,
			`You may be able to resolve the issue by addressing the concern and trying again.`
		].join("\n\n");
	}
	const eventId = require_logging.logIssue(error);
	return [
		"**Error**",
		"It looks like there was a problem communicating with the Sentry API.",
		"Please report the following to the user for the Sentry team:",
		`**Event ID**: ${eventId}`,
		process.env.NODE_ENV !== "production" ? error instanceof Error ? error.message : String(error) : ""
	].filter(Boolean).join("\n\n");
}

//#endregion
Object.defineProperty(exports, 'formatErrorForUser', {
  enumerable: true,
  get: function () {
    return formatErrorForUser;
  }
});
Object.defineProperty(exports, 'isApiClientError', {
  enumerable: true,
  get: function () {
    return isApiClientError;
  }
});
Object.defineProperty(exports, 'isApiError', {
  enumerable: true,
  get: function () {
    return isApiError;
  }
});
Object.defineProperty(exports, 'isApiServerError', {
  enumerable: true,
  get: function () {
    return isApiServerError;
  }
});
Object.defineProperty(exports, 'isConfigurationError', {
  enumerable: true,
  get: function () {
    return isConfigurationError;
  }
});
Object.defineProperty(exports, 'isUserInputError', {
  enumerable: true,
  get: function () {
    return isUserInputError;
  }
});
//# sourceMappingURL=error-handling-ZVmZRXZb.cjs.map