/*
 * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed 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.
 */

function isApiErrorLike(error) {
  return "statusCode" in error && typeof error.statusCode === "number";
}
function formatByStatusCode(error) {
  const statusCode = error.statusCode;
  if (statusCode === 401) {
    return {
      title: "Session expired",
      remediation: "Sign in again to continue."
    };
  }
  if (statusCode === 403) {
    return {
      title: "Permission denied",
      remediation: "Contact your administrator for permission."
    };
  }
  if (statusCode === 404) {
    return {
      title: "Not found",
      remediation: "The requested classification data could not be found."
    };
  }
  if (statusCode !== undefined && statusCode >= 500) {
    return {
      title: "Server error",
      remediation: "Something went wrong. Try again later."
    };
  }
  if (typeof error.errorDescription === "string" && error.errorDescription.length > 0) {
    return {
      title: error.errorDescription,
      remediation: ""
    };
  }
  return {
    title: error.message || "Something went wrong",
    remediation: ""
  };
}
export function formatCbacError(error) {
  if (error instanceof AggregateError && error.errors.length > 0) {
    const first = error.errors[0];
    if (first instanceof Error) {
      return formatCbacError(first);
    }
  }
  if (isApiErrorLike(error)) {
    return formatByStatusCode(error);
  }
  if (error.message.toLowerCase().includes("network") || error.message.toLowerCase().includes("fetch")) {
    return {
      title: "Network error",
      remediation: "Check your connection and try again."
    };
  }
  return {
    title: error.message || "Something went wrong",
    remediation: ""
  };
}
//# sourceMappingURL=errorMessages.js.map