pdf-preview-error.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import PropTypes from 'prop-types'
  2. import { useTranslation, Trans } from 'react-i18next'
  3. import { memo } from 'react'
  4. import PdfLogEntry from './pdf-log-entry'
  5. function PdfPreviewError({ error }) {
  6. const { t } = useTranslation()
  7. switch (error) {
  8. case 'rendering-error':
  9. return (
  10. <ErrorLogEntry title={t('pdf_rendering_error')}>
  11. {t('something_went_wrong_rendering_pdf')}
  12. </ErrorLogEntry>
  13. )
  14. case 'clsi-maintenance':
  15. return (
  16. <ErrorLogEntry title={t('server_error')}>
  17. {t('clsi_maintenance')}
  18. </ErrorLogEntry>
  19. )
  20. case 'clsi-unavailable':
  21. return (
  22. <ErrorLogEntry title={t('server_error')}>
  23. {t('clsi_unavailable')}
  24. </ErrorLogEntry>
  25. )
  26. case 'too-recently-compiled':
  27. return (
  28. <ErrorLogEntry title={t('server_error')}>
  29. {t('too_recently_compiled')}
  30. </ErrorLogEntry>
  31. )
  32. case 'terminated':
  33. return (
  34. <ErrorLogEntry title={t('terminated')}>
  35. {t('compile_terminated_by_user')}
  36. </ErrorLogEntry>
  37. )
  38. case 'rate-limited':
  39. return (
  40. <ErrorLogEntry title={t('pdf_compile_rate_limit_hit')}>
  41. {t('project_flagged_too_many_compiles')}
  42. </ErrorLogEntry>
  43. )
  44. case 'compile-in-progress':
  45. return (
  46. <ErrorLogEntry title={t('pdf_compile_in_progress_error')}>
  47. {t('pdf_compile_try_again')}
  48. </ErrorLogEntry>
  49. )
  50. case 'auto-compile-disabled':
  51. return (
  52. <ErrorLogEntry title={t('autocompile_disabled')}>
  53. {t('autocompile_disabled_reason')}
  54. </ErrorLogEntry>
  55. )
  56. case 'project-too-large':
  57. return (
  58. <ErrorLogEntry title={t('project_too_large')}>
  59. {t('project_too_much_editable_text')}
  60. </ErrorLogEntry>
  61. )
  62. case 'timedout':
  63. return (
  64. <ErrorLogEntry title={t('timedout')}>
  65. {t('proj_timed_out_reason')}
  66. <div>
  67. <a
  68. href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F"
  69. target="_blank"
  70. rel="noopener"
  71. >
  72. {t('learn_how_to_make_documents_compile_quickly')}
  73. </a>
  74. </div>
  75. </ErrorLogEntry>
  76. )
  77. case 'failure':
  78. return (
  79. <ErrorLogEntry title={t('no_pdf_error_title')}>
  80. {t('no_pdf_error_explanation')}
  81. <ul className="log-entry-formatted-content-list">
  82. <li>{t('no_pdf_error_reason_unrecoverable_error')}</li>
  83. <li>
  84. <Trans
  85. i18nKey="no_pdf_error_reason_no_content"
  86. components={{ code: <code /> }}
  87. />
  88. </li>
  89. <li>
  90. <Trans
  91. i18nKey="no_pdf_error_reason_output_pdf_already_exists"
  92. components={{ code: <code /> }}
  93. />
  94. </li>
  95. </ul>
  96. </ErrorLogEntry>
  97. )
  98. case 'clear-cache':
  99. return (
  100. <ErrorLogEntry title={t('server_error')}>
  101. {t('somthing_went_wrong_compiling')}
  102. </ErrorLogEntry>
  103. )
  104. case 'pdf-viewer-loading-error':
  105. return (
  106. <ErrorLogEntry title={t('pdf_rendering_error')}>
  107. <Trans
  108. i18nKey="something_went_wrong_loading_pdf_viewer"
  109. components={[
  110. <strong key="strong-" />,
  111. // eslint-disable-next-line jsx-a11y/anchor-has-content
  112. <a
  113. key="learn-link"
  114. target="_blank"
  115. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  116. />,
  117. // eslint-disable-next-line jsx-a11y/anchor-has-content
  118. <a key="contact-link" target="_blank" href="/contact" />,
  119. ]}
  120. />
  121. </ErrorLogEntry>
  122. )
  123. case 'validation-problems':
  124. return null // handled elsewhere
  125. case 'error':
  126. default:
  127. return (
  128. <ErrorLogEntry title={t('server_error')}>
  129. {t('somthing_went_wrong_compiling')}
  130. </ErrorLogEntry>
  131. )
  132. }
  133. }
  134. PdfPreviewError.propTypes = {
  135. error: PropTypes.string.isRequired,
  136. }
  137. export default memo(PdfPreviewError)
  138. function ErrorLogEntry({ title, children }) {
  139. const { t } = useTranslation()
  140. return (
  141. <PdfLogEntry
  142. headerTitle={title}
  143. formattedContent={children}
  144. entryAriaLabel={t('compile_error_entry_description')}
  145. level="error"
  146. />
  147. )
  148. }
  149. ErrorLogEntry.propTypes = {
  150. title: PropTypes.string.isRequired,
  151. children: PropTypes.any.isRequired,
  152. }