refactor: created custom error for a token already exists
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user