forked from ChatGPTNextWeb/NextChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…l errors
- Loading branch information
Showing
9 changed files
with
107 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from "react"; | ||
import { IconButton } from "./button"; | ||
import GithubIcon from "../icons/github.svg"; | ||
import { ISSUE_URL } from "../constant"; | ||
|
||
interface IErrorBoundaryState { | ||
hasError: boolean; | ||
error: Error | null; | ||
info: React.ErrorInfo | null; | ||
} | ||
|
||
export class ErrorBoundary extends React.Component<any, IErrorBoundaryState> { | ||
constructor(props: any) { | ||
super(props); | ||
this.state = { hasError: false, error: null, info: null }; | ||
} | ||
|
||
componentDidCatch(error: Error, info: React.ErrorInfo) { | ||
// Update state with error details | ||
this.setState({ hasError: true, error, info }); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
// Render error message | ||
return ( | ||
<div className="error"> | ||
<h2>Oops, something went wrong!</h2> | ||
<pre> | ||
<code>{this.state.error?.toString()}</code> | ||
<code>{this.state.info?.componentStack}</code> | ||
</pre> | ||
|
||
<a href={ISSUE_URL} className="report"> | ||
<IconButton | ||
text="Report This Error" | ||
icon={<GithubIcon />} | ||
bordered | ||
/> | ||
</a> | ||
</div> | ||
); | ||
} | ||
// if no error occurred, render children | ||
return this.props.children; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export const OWNER = "Yidadaa"; | ||
export const REPO = "ChatGPT-Next-Web"; | ||
export const REPO_URL = `https://github.com/${OWNER}/${REPO}`; | ||
export const ISSUE_URL = `https://github.com/${OWNER}/${REPO}/issues`; | ||
export const UPDATE_URL = `${REPO_URL}#%E4%BF%9D%E6%8C%81%E6%9B%B4%E6%96%B0-keep-updated`; | ||
export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/commits?per_page=1`; | ||
export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
declare global { | ||
interface Array<T> { | ||
at(index: number): T | undefined; | ||
} | ||
} | ||
|
||
if (!Array.prototype.at) { | ||
Array.prototype.at = function (index: number) { | ||
// Get the length of the array | ||
const length = this.length; | ||
|
||
// Convert negative index to a positive index | ||
if (index < 0) { | ||
index = length + index; | ||
} | ||
|
||
// Return undefined if the index is out of range | ||
if (index < 0 || index >= length) { | ||
return undefined; | ||
} | ||
|
||
// Use Array.prototype.slice method to get value at the specified index | ||
return Array.prototype.slice.call(this, index, index + 1)[0]; | ||
}; | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters