refactor: created custom error for a token already exists

This commit is contained in:
2024-06-16 08:47:07 -04:00
parent f9d7a6bbd2
commit 3b1fe66261
3 changed files with 9 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import { env } from "hono/adapter";
import mapKeys from "lodash.mapkeys";
import { Case, changeStringCase } from "~/libs/changeStringCase";
import { TokenAlreadyExistsError } from "~/libs/errors/TokenAlreadyExists";
import type { AdminSdkCredentials } from "~/libs/fcm/getGoogleAuthToken";
import { verifyFcmToken } from "~/libs/fcm/verifyFcmToken";
import { readEnvVariable } from "~/libs/readEnvVariable";
@@ -69,7 +70,7 @@ app.openapi(route, async (c) => {
await saveToken(env(c, "workerd"), deviceId, token, username);
} catch (error) {
if (error.message === "Token already exists in the database") {
if (error instanceof TokenAlreadyExistsError) {
return c.json(ErrorResponse, 412);
}