gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

error.jsx (2351B)


      1 /*
      2 	GoToSocial
      3 	Copyright (C) GoToSocial Authors admin@gotosocial.org
      4 	SPDX-License-Identifier: AGPL-3.0-or-later
      5 
      6 	This program is free software: you can redistribute it and/or modify
      7 	it under the terms of the GNU Affero General Public License as published by
      8 	the Free Software Foundation, either version 3 of the License, or
      9 	(at your option) any later version.
     10 
     11 	This program is distributed in the hope that it will be useful,
     12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 	GNU Affero General Public License for more details.
     15 
     16 	You should have received a copy of the GNU Affero General Public License
     17 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
     18 */
     19 
     20 "use strict";
     21 
     22 const React = require("react");
     23 
     24 function ErrorFallback({ error, resetErrorBoundary }) {
     25 	return (
     26 		<div className="error">
     27 			<p>
     28 				{"An error occured, please report this on the "}
     29 				<a href="https://github.com/superseriousbusiness/gotosocial/issues">GoToSocial issue tracker</a>
     30 				{" or "}
     31 				<a href="https://matrix.to/#/#gotosocial-help:superseriousbusiness.org">Matrix support room</a>.
     32 				<br />Include the details below:
     33 			</p>
     34 			<div className="details">
     35 				<pre>
     36 					{error.name}: {error.message}
     37 				</pre>
     38 				<pre>
     39 					{error.stack}
     40 				</pre>
     41 			</div>
     42 			<p>
     43 				<button onClick={resetErrorBoundary}>Try again</button> or <a href="">refresh the page</a>
     44 			</p>
     45 		</div>
     46 	);
     47 }
     48 
     49 function Error({ error }) {
     50 	/* eslint-disable-next-line no-console */
     51 	console.error("Rendering error:", error);
     52 	let message;
     53 
     54 	if (error.data != undefined) { // RTK Query error with data
     55 		if (error.status) {
     56 			message = (<>
     57 				<b>{error.status}:</b> {error.data.error}
     58 				{error.data.error_description &&
     59 					<p>
     60 						{error.data.error_description}
     61 					</p>
     62 				}
     63 			</>);
     64 		} else {
     65 			message = error.data.error;
     66 		}
     67 	} else if (error.name != undefined || error.type != undefined) { // JS error
     68 		message = (<>
     69 			<b>{error.type && error.name}:</b> {error.message}
     70 		</>);
     71 	} else if (error.status && typeof error.error == "string") {
     72 		message = (<>
     73 			<b>{error.status}:</b> {error.error}
     74 		</>);
     75 	} else {
     76 		message = error.message ?? error;
     77 	}
     78 
     79 	return (
     80 		<div className="error">
     81 			{message}
     82 		</div>
     83 	);
     84 }
     85 
     86 module.exports = { ErrorFallback, Error };