Skip to content

Commit

Permalink
handleError: Refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
gampig committed Sep 23, 2023
1 parent 1c54059 commit 5531bc0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/utils/store/handleError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { showError } from "@/utils/notifications";
import de from "@/firebase/locales/de";
import ErrorReportBuilder from "@/services/errorReport";

function translateError(code?: string): string | null {
if (code === undefined) {
return null;
}
function translateFirebaseError(code: string): string | null {
const translation = code
.split("/")
.reduce(
Expand All @@ -19,9 +16,14 @@ function translateError(code?: string): string | null {
return translation;
}

export default function (error: Error & { code?: string }) {
const message = translateError(error.code) || error.message;
showError(message);
export default function (error: Error | firebase.default.FirebaseError) {
let translatedErrorMessage = null;

if ("code" in error) {
translatedErrorMessage = translateFirebaseError(error.code);
}

showError(translatedErrorMessage || error.message);

new ErrorReportBuilder(false).addException(error).getReport().send();
}

0 comments on commit 5531bc0

Please sign in to comment.