Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/api/src/api/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Request, Response } from "express";
import logger from "../../config/logger";
import User from "../../models/user.model";
import { SupabaseAuthService } from "../services/auth";

Expand All @@ -24,7 +25,7 @@ export class AuthController {
exists
});
} catch (error) {
console.error("Error in checkEmail:", error);
logger.error("Error in checkEmail:", error);
return res.status(500).json({
error: "Failed to check email"
});
Expand Down Expand Up @@ -58,7 +59,7 @@ export class AuthController {
success: true
});
} catch (error) {
console.error("Error in requestOTP:", error);
logger.error("Error in requestOTP:", error);
return res.status(500).json({
error: "Failed to send OTP"
});
Expand Down Expand Up @@ -94,7 +95,7 @@ export class AuthController {
user_id: result.user_id
});
} catch (error) {
console.error("Error in verifyOTP:", error);
logger.error("Error in verifyOTP:", error);
return res.status(400).json({
error: "Invalid OTP or OTP expired"
});
Expand Down Expand Up @@ -123,7 +124,7 @@ export class AuthController {
success: true
});
} catch (error) {
console.error("Error in refreshToken:", error);
logger.error("Error in refreshToken:", error);
return res.status(401).json({
error: "Invalid refresh token"
});
Expand Down Expand Up @@ -158,7 +159,7 @@ export class AuthController {
valid: true
});
} catch (error) {
console.error("Error in verifyToken:", error);
logger.error("Error in verifyToken:", error);
return res.status(401).json({
error: "Token verification failed",
valid: false
Expand Down
11 changes: 6 additions & 5 deletions apps/api/src/api/controllers/brla.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { Request, Response } from "express";
import httpStatus from "http-status";
import { Op } from "sequelize";
import logger from "../../config/logger";
import TaxId, { TaxIdInternalStatus } from "../../models/taxId.model";
import { APIError } from "../errors/api-error";

Expand Down Expand Up @@ -96,7 +97,7 @@ function mapKycFailureReason(webhookReason: string | undefined): KycFailureReaso

// Helper function to use in the catch block of the controller functions.
function handleApiError(error: unknown, res: Response, apiMethod: string): void {
console.error(`Error while performing ${apiMethod}: `, error);
logger.error(`Error while performing ${apiMethod}: `, error);

if (error instanceof Error && error.message.includes("status '400'")) {
const splitError = error.message.split("Error: ", 1);
Expand Down Expand Up @@ -174,7 +175,7 @@ export const getAveniaUser = async (
});
return;
} catch (error) {
console.log(error);
logger.info(error);
if (
error instanceof Error &&
(error.message.includes("sub-account-id does not exist") || error.message.includes("sub-account-id is invalid"))
Expand Down Expand Up @@ -335,7 +336,7 @@ export const createSubaccount = async (

res.status(httpStatus.OK).json({ subAccountId: id });
} catch (error) {
console.error("Error creating subaccount:", error);
logger.error("Error creating subaccount:", error);
handleApiError(error, res, "createSubaccount");
}
};
Expand Down Expand Up @@ -465,7 +466,7 @@ export const getSelfieLivenessUrl = async (
validateLivenessToken: selfieUrl.validateLivenessToken ?? ""
});
} catch (error) {
console.error(error);
logger.error(error);
handleApiError(error, res, "getSelfieLivenessUrl");
}
};
Expand Down Expand Up @@ -536,7 +537,7 @@ export const getUploadUrls = async (
}
});
} catch (error) {
console.error(error);
logger.error(error);
handleApiError(error, res, "getUploadUrls");
}
};
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/api/controllers/googleSpreadSheet.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "dotenv/config";
import { Request, Response } from "express";
import httpStatus from "http-status";
import logger from "../../config/logger";
import { config } from "../../config/vars";
import { APIError } from "../errors/api-error";
import { appendData, GoogleCredentials, getOrCreateSheet, initGoogleSpreadsheet } from "../services/spreadsheet.service";
Expand Down Expand Up @@ -44,7 +45,7 @@ export async function storeDataInGoogleSpreadsheet(
await appendData(sheet, req.body);
return res.status(httpStatus.OK).json({ message: "Data stored successfully" });
} catch (error) {
console.error("Error in storeData:", error);
logger.error("Error in storeData:", error);
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
details: errorMessage,
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/api/controllers/monerium.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Networks } from "@vortexfi/shared";
import { Request, Response } from "express";
import httpStatus from "http-status";
import logger from "../../config/logger";
import { checkAddressExists } from "../services/monerium";

export const checkAddressExistsController = async (req: Request, res: Response): Promise<void> => {
Expand All @@ -24,7 +25,7 @@ export const checkAddressExistsController = async (req: Request, res: Response):
res.status(httpStatus.NOT_FOUND).json({ error: "Address not found" });
}
} catch (error) {
console.error("Error in checkAddressExistsController:", error);
logger.error("Error in checkAddressExistsController:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: "Internal Server Error" });
}
};
7 changes: 4 additions & 3 deletions apps/api/src/api/controllers/moonbeam.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Request, Response } from "express";
import httpStatus from "http-status";
import { Address, encodeFunctionData } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import logger from "../../config/logger";
import {
MOONBEAM_EXECUTOR_PRIVATE_KEY,
MOONBEAM_FUNDING_AMOUNT_UNITS,
Expand Down Expand Up @@ -60,12 +61,12 @@ export const executeXcmController = async (
res.json({ hash });
return;
} catch (error) {
console.error("Error executing XCM:", error);
logger.error("Error executing XCM:", error);
res.status(httpStatus.BAD_REQUEST).json({ error: "Invalid transaction" });
return;
}
} catch (error) {
console.error("Error executing XCM:", error);
logger.error("Error executing XCM:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: "Internal Server Error" });
}
};
Expand All @@ -92,7 +93,7 @@ export const sendStatusWithPk = async (): Promise<StatusResponse> => {

return { public: moonbeamExecutorAccount.address, status: true };
} catch (error) {
console.error("Error fetching Moonbeam executor balance:", error);
logger.error("Error fetching Moonbeam executor balance:", error);
return { public: moonbeamExecutorAccount?.address, status: false };
}
};
2 changes: 1 addition & 1 deletion apps/api/src/api/controllers/pendulum.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const fundEphemeralAccountController = async (
res.status(httpStatus.INTERNAL_SERVER_ERROR).send({ error: "Funding error" });
return;
} catch (error) {
console.error("Error funding ephemeral account:", error);
logger.error("Error funding ephemeral account:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).send({ error: "Internal Server Error" });
}
};
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/api/controllers/price.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@vortexfi/shared";
import { RequestHandler } from "express";
import httpStatus from "http-status";

import logger from "../../config/logger";
import {
InvalidAmountError,
InvalidParameterError,
Expand Down Expand Up @@ -110,10 +110,10 @@ export const getPriceForProvider: RequestHandler<unknown, unknown, unknown, Pric
res.status(httpStatus.BAD_REQUEST).json({ error: err.message });
} else if (err instanceof ProviderInternalError) {
// 502 Bad Gateway: The upstream provider had an internal issue. Log it.
console.error("Provider internal error:", err);
logger.error("Provider internal error:", err);
res.status(httpStatus.BAD_GATEWAY).json({ error: err.message });
} else {
console.error("Unexpected server error:", err);
logger.error("Unexpected server error:", err);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
error: "An internal server error occurred while fetching the price."
});
Expand Down Expand Up @@ -200,10 +200,10 @@ export const getAllPricesBundled: RequestHandler<
} else if (reason instanceof Error) {
// Generic JS Error
errorMessage = reason.message;
console.error(`Non-provider error for ${provider}:`, reason); // Log unexpected errors
logger.error(`Non-provider error for ${provider}:`, reason); // Log unexpected errors
} else {
// Unknown error type
console.error(`Unknown error type for ${provider}:`, reason);
logger.error(`Unknown error type for ${provider}:`, reason);
}

response[provider] = {
Expand All @@ -215,7 +215,7 @@ export const getAllPricesBundled: RequestHandler<
// This case indicates an issue with the Promise.allSettled structure itself or the mapping,
// as our inner promises are designed to catch their errors.
// Log this unexpected scenario for debugging.
console.error("Unexpected Promise.allSettled rejection:", result.reason);
logger.error("Unexpected Promise.allSettled rejection:", result.reason);
// For now, we won't add an entry for this provider if the outer promise rejects.
}
});
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/api/controllers/siwe.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@vortexfi/shared";
import { Request, Response } from "express";
import httpStatus from "http-status";
import logger from "../../config/logger";
import { DEFAULT_LOGIN_EXPIRATION_TIME_HOURS } from "../../constants/constants";
import { createAndSendNonce, validateSignatureAndGetMemo, verifyAndStoreSiweMessage } from "../services/siwe.service";

Expand All @@ -26,7 +27,7 @@ export const sendSiweMessage = async (
res.json({ nonce });
return;
} catch (error) {
console.error("Nonce generation error:", error);
logger.error("Nonce generation error:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: "Error while generating nonce" });
}
};
Expand Down Expand Up @@ -57,7 +58,7 @@ export const validateSiweSignature = async (
res.json({ message: "Signature is valid" });
return;
} catch (error) {
console.error("Signature validation error:", error);
logger.error("Signature validation error:", error);

if (error instanceof Error && error.name === "SiweValidationError") {
res.status(httpStatus.UNAUTHORIZED).json({ error: `Siwe validation error: ${error.message}` });
Expand Down Expand Up @@ -97,7 +98,7 @@ export const checkAuth = async (req: Request, res: Response): Promise<void> => {
res.status(httpStatus.UNAUTHORIZED).json({ error: "Invalid authentication token." });
}
} catch (error) {
console.error("Auth check error:", error);
logger.error("Auth check error:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: "An error occurred during authentication check." });
}
};
9 changes: 5 additions & 4 deletions apps/api/src/api/controllers/stellar.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { NextFunction, Request, Response } from "express";
import httpStatus from "http-status";
import { Keypair } from "stellar-sdk";
import logger from "../../config/logger";
import { FUNDING_SECRET, SEP10_MASTER_SECRET, STELLAR_FUNDING_AMOUNT_UNITS } from "../../constants/constants";
import { signSep10Challenge } from "../services/sep10/sep10.service";
import { SlackNotifier } from "../services/slack.service";
Expand All @@ -35,7 +36,7 @@ export const createStellarTransactionHandler = async (
res.json({ public: FUNDING_PUBLIC_KEY, sequence, signature });
return;
} catch (error) {
console.error("Error in createStellarTransaction:", error);
logger.error("Error in createStellarTransaction:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
details: (error as Error).message,
error: "Failed to create transaction"
Expand Down Expand Up @@ -63,7 +64,7 @@ export const signSep10ChallengeHandler = async (
});
return;
} catch (error) {
console.error("Error in signSep10Challenge:", error);
logger.error("Error in signSep10Challenge:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
details: (error as Error).message,
error: "Failed to sign challenge"
Expand All @@ -84,7 +85,7 @@ export const getSep10MasterPKHandler = async (
res.json({ masterSep10Public });
return;
} catch (error) {
console.error("Error in getSep10MasterPK:", error);
logger.error("Error in getSep10MasterPK:", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
details: (error as Error).message,
error: "Failed to get master public key"
Expand Down Expand Up @@ -117,7 +118,7 @@ export async function sendStatusWithPk(): Promise<StatusResult> {

return { public: FUNDING_PUBLIC_KEY, status: true };
} catch (error) {
console.error("Couldn't load Stellar account:", error);
logger.error("Couldn't load Stellar account:", error);
return { public: FUNDING_PUBLIC_KEY, status: false };
}
}
4 changes: 2 additions & 2 deletions apps/api/src/api/controllers/subsidize.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const subsidizePreSwap = async (
res.json({ message: "Subsidy transferred successfully" });
return;
} catch (error) {
console.error("Error in subsidizePreSwap::", error);
logger.error("Error in subsidizePreSwap::", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
details: error instanceof Error ? error.message : "Unknown error",
error: "Server error"
Expand Down Expand Up @@ -97,7 +97,7 @@ export const subsidizePostSwap = async (
res.json({ message: "Subsidy transferred successfully" });
return;
} catch (error) {
console.error("Error in subsidizePostSwap::", error);
logger.error("Error in subsidizePostSwap::", error);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
details: error instanceof Error ? error.message : "Unknown error",
error: "Server error"
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/api/middlewares/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextFunction, Request, Response } from "express";
import httpStatus from "http-status";
import logger from "../../config/logger";
import { validateSignatureAndGetMemo } from "../services/siwe.service";

declare global {
Expand Down Expand Up @@ -60,7 +61,7 @@ async function getMemoFromCookiesMiddleware(req: Request, res: Response, next: N
return;
}

console.error(`Error in getMemoFromCookiesMiddleware: ${err.message}`);
logger.error(`Error in getMemoFromCookiesMiddleware: ${err.message}`);
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
details: err.message,
error: "Error while verifying signature"
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/api/middlewares/supabaseAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function requireAuth(req: Request, res: Response, next: NextFunctio
req.userId = result.user_id;
next();
} catch (error) {
console.error("Auth middleware error:", error);
logger.error("Auth middleware error:", error);
return res.status(401).json({
error: "Authentication failed"
});
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/api/middlewares/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "@vortexfi/shared";
import { RequestHandler } from "express";
import httpStatus from "http-status";
import logger from "../../config/logger";
import { CONTACT_SHEET_HEADER_VALUES } from "../controllers/contact.controller";
import { EMAIL_SHEET_HEADER_VALUES } from "../controllers/email.controller";
import { RATING_SHEET_HEADER_VALUES } from "../controllers/rating.controller";
Expand Down Expand Up @@ -253,7 +254,7 @@ const validateRequestBodyValues =
if (!requiredRequestBodyKeys.every(key => data[key])) {
const missingItems = requiredRequestBodyKeys.filter(key => !data[key]);
const errorMessage = `Request body data does not match schema. Missing items: ${missingItems.join(", ")}`;
console.error(errorMessage);
logger.error(errorMessage);
res.status(httpStatus.BAD_REQUEST).json({ error: errorMessage });
return;
}
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/api/services/alchemypay/alchemypay.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AlchemyPayPriceResponse, RampDirection } from "@vortexfi/shared";
import logger from "../../../config/logger";
import { ProviderInternalError } from "../../errors/providerErrors";
import { createQuoteRequest } from "./request-creator";
import { AlchemyPayResponse, processAlchemyPayResponse } from "./response-handler";
Expand All @@ -21,7 +22,7 @@ async function fetchAlchemyPayData(url: string, request: RequestInit): Promise<F
const body = (await response.json()) as AlchemyPayResponse;
return { body, response };
} catch (fetchError) {
console.error("AlchemyPay fetch error:", fetchError);
logger.error("AlchemyPay fetch error:", fetchError);
throw new ProviderInternalError(`Network error fetching price from AlchemyPay: ${(fetchError as Error).message}`);
}
}
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/api/services/alchemypay/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logger from "../../../config/logger";

/**
* Remove empty keys from an object
* @param map The object to remove empty keys from
Expand Down Expand Up @@ -92,7 +94,7 @@ export function getJsonBody(body: string): string {
map = JSON.parse(body);
} catch (error) {
map = {};
console.error("Couldn't parse JSON body", error);
logger.error("Couldn't parse JSON body", error);
}

if (Object.keys(map).length === 0) {
Expand Down
Loading
Loading