Skip to content

Commit

Permalink
domain name error
Browse files Browse the repository at this point in the history
  • Loading branch information
williamsjokvist committed Nov 5, 2024
1 parent 06f46e6 commit 99bc037
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ func (ch *CommandHandler) SaveTheme(theme model.ThemeName) error {
return nil
}

func (ch *CommandHandler) GetFormattedErrorModelUnused() *model.FormattedError {
func (ch *CommandHandler) GetFGCTrackerErrorModelUnused() *model.FGCTrackerError {
return nil
}
16 changes: 8 additions & 8 deletions gui/src/main/app-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AppTitleBar } from './app-titlebar'
import { LocalizationKey } from './i18n'

export function AppErrorBoundary() {
const err = useFormattedError()
const err = useFGCTrackerError()
return (
<ErrorWrapper err={err}>
<AppTitleBar />
Expand All @@ -21,7 +21,7 @@ export function AppErrorBoundary() {

export function PageErrorBoundary() {
const { t } = useTranslation()
const err = useFormattedError()
const err = useFGCTrackerError()
if (!err?.localizationKey) {
return null
}
Expand All @@ -34,25 +34,25 @@ export function PageErrorBoundary() {
)
}

const isFormattedError = (error: unknown) => error instanceof Object && 'translationKey' in error
const isFGCTrackerError = (error: unknown) => error instanceof Object && 'translationKey' in error

function useFormattedError() {
function useFGCTrackerError() {
const thrownError = useRouteError()
const [err, setErr] = React.useState<model.FormattedError | unknown>()
const [err, setErr] = React.useState<model.FGCTrackerError | unknown>()

React.useEffect(() => {
console.error(thrownError)
if (thrownError instanceof Error) {
setErr({ translationKey: '', message: thrownError.message, error: thrownError })
} else if (isFormattedError(thrownError)) {
} else if (isFGCTrackerError(thrownError)) {
setErr(thrownError)
}
}, [thrownError])

return err as model.FormattedError
return err as model.FGCTrackerError
}

function ErrorWrapper(props: React.PropsWithChildren & { err?: model.FormattedError }) {
function ErrorWrapper(props: React.PropsWithChildren & { err?: model.FGCTrackerError }) {
const { t } = useTranslation()
if (!props.err) {
return null
Expand Down
6 changes: 3 additions & 3 deletions gui/src/main/error-popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import { cn } from '@/helpers/cn'
import type { LocalizationKey } from './i18n'

type ErrorContextType = [
error: model.FormattedError | null,
setError: React.Dispatch<model.FormattedError>
error: model.FGCTrackerError | null,
setError: React.Dispatch<model.FGCTrackerError>
]
const ErrorContext = React.createContext<ErrorContextType | null>(null)
export const useErrorPopup = () => React.useContext(ErrorContext)![1]

export function ErrorPopupProvider(props: React.PropsWithChildren) {
const { t } = useTranslation()
const [scope, animate] = useAnimate()
const [error, setError] = React.useState<model.FormattedError | null>(null)
const [error, setError] = React.useState<model.FGCTrackerError | null>(null)

React.useEffect(() => {
if (error === null) {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/state/auth-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TRACKING_MACHINE } from './tracking-machine'
type AuthMachineContextProps = {
progress: number
game?: model.GameType
error: model.FormattedError | null
error: model.FGCTrackerError | null
}
export const AUTH_MACHINE = setup({
types: {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/state/tracking-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type TrackingMachineContextProps = {
restore: boolean
isTracking: boolean
match: model.Match
error: model.FormattedError | null
error: model.FGCTrackerError | null
}

export const TRACKING_MACHINE = setup({
Expand Down
2 changes: 1 addition & 1 deletion gui/wailsjs/go/cmd/CommandHandler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function CheckForUpdate():Promise<boolean>;

export function GetAppVersion():Promise<string>;

export function GetFormattedErrorModelUnused():Promise<model.FormattedError>;
export function GetFGCTrackerErrorModelUnused():Promise<model.FGCTrackerError>;

export function GetGuiConfig():Promise<model.GuiConfig>;

Expand Down
8 changes: 4 additions & 4 deletions gui/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,20 @@ export namespace model {
errOpenResultsDirectory = "errOpenResultsDirectory",
errReadThemeCSS = "errReadThemeCSS",
}
export class FormattedError {
export class FGCTrackerError {
localizationKey: ErrorLocalizationKey;
message: string;
error: any;
InnerError: any;

static createFrom(source: any = {}) {
return new FormattedError(source);
return new FGCTrackerError(source);
}

constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.localizationKey = source["localizationKey"];
this.message = source["message"];
this.error = source["error"];
this.InnerError = source["InnerError"];
}
}
export class GuiConfig {
Expand Down
30 changes: 15 additions & 15 deletions pkg/model/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,43 +67,43 @@ var (
ErrReadThemeCSS = newError(tKeyErrReadThemeCSS, errors.New("read theme css"))
)

type FormattedError struct {
ErrorLocalizationKey ErrorLocalizationKey `json:"localizationKey"`
Message string `json:"message"`
InnerError error `json:"error"`
type FGCTrackerError struct {
LocalizationKey ErrorLocalizationKey `json:"localizationKey"`
Message string `json:"message"`
InnerError error
}

func NewError(fmtErr *FormattedError, err error) *FormattedError {
func NewError(fmtErr *FGCTrackerError, err error) *FGCTrackerError {
fmtErr.InnerError = fmt.Errorf("%w: %w", fmtErr.InnerError, err)
return fmtErr
}

func newError(key ErrorLocalizationKey, err error) *FormattedError {
return &FormattedError{
ErrorLocalizationKey: key,
InnerError: err,
func newError(key ErrorLocalizationKey, err error) *FGCTrackerError {
return &FGCTrackerError{
LocalizationKey: key,
InnerError: err,
}
}

func (e *FormattedError) Error() string {
func (e *FGCTrackerError) Error() string {
return e.InnerError.Error()
}

func (e *FormattedError) Unwrap() error {
func (e *FGCTrackerError) Unwrap() error {
return e.InnerError
}

func ContainsFormattedError(err error) bool {
var trackingErr *FormattedError
func ContainsFGCTrackerError(err error) bool {
var trackingErr *FGCTrackerError
return errors.As(err, &trackingErr)
}

func FormatError(err error) any {
var formattedErr *FormattedError
var formattedErr *FGCTrackerError
var message string
var localizationKey ErrorLocalizationKey
if errors.As(err, &formattedErr) {
localizationKey = formattedErr.ErrorLocalizationKey
localizationKey = formattedErr.LocalizationKey
message = formattedErr.InnerError.Error()
}

Expand Down

0 comments on commit 99bc037

Please sign in to comment.