<commit_before>import * as React from 'react'
import * as Modals from '../Modals';
import { Dic } from '../Globals';
import { ajaxPost, ExternalServiceError, ServiceError, ValidationError } from '../Services';
import { JavascriptMessage, FrameMessage, ConnectionMessage } from '../Signum.Entities'
import { ClientErrorModel, ExceptionEntity } from '../Signum.Entities.Basics'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import "./Modals.css"
import { newLite } from '../Reflection';
import { Modal } from 'react-bootstrap';
import MessageModal from './MessageModal';
import { namespace } from 'd3';

//http://codepen.io/m-e-conroy/pen/ALsdF
interface ErrorModalProps extends Modals.IModalProps<undefined> {
  error: any;
}

export default function ErrorModal(p: ErrorModalProps) {

  const [show, setShow] = React.useState(true);

  function handleOnExited() {
    p.onExited!(undefined);
  }

  function handleCloseClicked() {
    setShow(false);
  }


  const e = p.error;

  const se = e instanceof ServiceError ? (e as ServiceError) : undefined;
  const ese = e instanceof ExternalServiceError ? (e as ExternalServiceError) : undefined;
  const ve = e instanceof ValidationError ? (e as ValidationError) : undefined;

  return (
    <Modal show={show} onExited={handleOnExited} onHide={handleCloseClicked} size="lg">
      <div className="modal-header dialog-header-error">
        <h5 className="modal-title">
          {
            se ? renderServiceTitle(se) :
              ve ? renderValidationTitle(ve) :
                ese ? renderExternalServiceTitle(ese) :
                  renderTitle(e)
          }
        </h5>
        <button type="button" className="btn-close" data-dismiss="modal" aria-label="Close" onClick={handleCloseClicked}/>
      </div>

      <div className="modal-body">
        {se ? ErrorModalOptions.renderServiceMessage(se) :
          ve ? ErrorModalOptions.renderValidationMessage(ve) :
            ese ? ErrorModalOptions.renderExternalServiceMessage(ese) :
            ErrorModalOptions.renderMessage(e)}
      </div>

      <div className="modal-footer">
        <button className="btn btn-primary sf-close-button sf-ok-button" onClick={handleCloseClicked}>
          {JavascriptMessage.ok.niceToString()}</button>
      </div>
    </Modal>
  );

  function renderTitle(e: any) {
    return (
      <span><FontAwesomeIcon icon="triangle-exclamation" /> Error </span>
    );
  }

  function renderServiceTitle(se: ServiceError) {
    return (
      <span>
        <FontAwesomeIcon icon={se.defaultIcon} />&nbsp; <span>{se.httpError.exceptionType}</span>
        {se.httpError.exceptionId && <span>({
          ErrorModalOptions.isExceptionViewable() ?
            <a href={ErrorModalOptions.getExceptionUrl(se.httpError.exceptionId!)}>{se.httpError.exceptionId}</a> :
            <strong>{se.httpError.exceptionId}</strong>
        })</span>}
      </span>
    );
  }

  function renderExternalServiceTitle(ese: ExternalServiceError) {
    return (
      <span>
        <strong>{ese.serviceName}: </strong>
        {ese.title}
      </span>
    );
  }


  function renderValidationTitle(ve: ValidationError) {
    return (
      <span>
        <FontAwesomeIcon icon="triangle-exclamation" /> {FrameMessage.ThereAreErrors.niceToString()}
      </span>
    );
  }
}



var lastError: { model: ClientErrorModel, date: Date } | undefined;

function logError(error: Error) {

  if (error instanceof ServiceError || error instanceof ValidationError)
    return; 

  var errorModel = ClientErrorModel.New({
    errorType: (error as Object).constructor.name,
    message: error.message ?? error.toString(),
    stack: error.stack ?? null,
    name: error.name,<commit_msg>fix ErrorModal<commit_after>import * as React from 'react'
import * as Modals from '../Modals';
import { Dic } from '../Globals';
import { ajaxPost, ExternalServiceError, ServiceError, ValidationError } from '../Services';
import { JavascriptMessage, FrameMessage, ConnectionMessage } from '../Signum.Entities'
import { ClientErrorModel, ExceptionEntity } from '../Signum.Entities.Basics'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import "./Modals.css"
import { newLite } from '../Reflection';
import { Modal } from 'react-bootstrap';
import MessageModal from './MessageModal';
import { namespace } from 'd3';

//http://codepen.io/m-e-conroy/pen/ALsdF
interface ErrorModalProps extends Modals.IModalProps<undefined> {
  error: any;
}

export default function ErrorModal(p: ErrorModalProps) {

  const [show, setShow] = React.useState(true);

  function handleOnExited() {
    p.onExited!(undefined);
  }

  function handleCloseClicked() {
    setShow(false);
  }


  const e = p.error;

  const se = e instanceof ServiceError ? (e as ServiceError) : undefined;
  const ese = e instanceof ExternalServiceError ? (e as ExternalServiceError) : undefined;
  const ve = e instanceof ValidationError ? (e as ValidationError) : undefined;

  return (
    <Modal show={show} onExited={handleOnExited} onHide={handleCloseClicked} size="lg">
      <div className="modal-header dialog-header-error">
        <h5 className="modal-title">
          {
            se ? renderServiceTitle(se) :
              ve ? renderValidationTitle(ve) :
                ese ? renderExternalServiceTitle(ese) :
                  renderTitle(e)
          }
        </h5>
        <button type="button" className="btn-close" data-dismiss="modal" aria-label="Close" onClick={handleCloseClicked}/>
      </div>

      <div className="modal-body">
        {se ? ErrorModalOptions.renderServiceMessage(se) :
          ve ? ErrorModalOptions.renderValidationMessage(ve) :
            ese ? ErrorModalOptions.renderExternalServiceMessage(ese) :
            ErrorModalOptions.renderMessage(e)}
      </div>

      <div className="modal-footer">
        <button className="btn btn-primary sf-close-button sf-ok-button" onClick={handleCloseClicked}>
          {JavascriptMessage.ok.niceToString()}</button>
      </div>
    </Modal>
  );

  function renderTitle(e: any) {
    return (
      <span><FontAwesomeIcon icon="triangle-exclamation" /> Error </span>
    );
  }

  function renderServiceTitle(se: ServiceError) {
    return (
      <span>
        <FontAwesomeIcon icon={se.defaultIcon} />&nbsp; <span>{se.httpError.exceptionType}</span>
        {se.httpError.exceptionId && <span>({
          ErrorModalOptions.isExceptionViewable() ?
            <a href={ErrorModalOptions.getExceptionUrl(se.httpError.exceptionId!)}>{se.httpError.exceptionId}</a> :
            <strong>{se.httpError.exceptionId}</strong>
        })</span>}
      </span>
    );
  }

  function renderExternalServiceTitle(ese: ExternalServiceError) {
    return (
      <span>
        <strong>{ese.serviceName}: </strong>
        {ese.title}
      </span>
    );
  }


  function renderValidationTitle(ve: ValidationError) {
    return (
      <span>
        <FontAwesomeIcon icon="triangle-exclamation" /> {FrameMessage.ThereAreErrors.niceToString()}
      </span>
    );
  }
}



var lastError: { model: ClientErrorModel, date: Date } | undefined;

function logError(error: Error) {

  if (error instanceof ServiceError || error instanceof ValidationError)
    return; 

  if (error instanceof DOMException && error.name == "AbortError")
    return;

  var errorModel = ClientErrorModel.New({
    errorType: (error as Object).constructor.name,
    message: error.message ?? error.toString(),
    stack: error.stack ?? null,
    name: error.name,
{'fraction_non_alphanumeric': 0.13035975043143502, 'fraction_numerical': 0.0007964954201513341, 'mean_word_length': 3.2492949802594473, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3213479', 'n_tokens_mistral': 2222, 'n_tokens_neox': 2144, 'n_words': 465}