Skip to content

Commit be4f8ee

Browse files
committed
error handling
1 parent 9d0f416 commit be4f8ee

File tree

4 files changed

+6
-92
lines changed

4 files changed

+6
-92
lines changed

tooling/sparta/packages/discord/src/api/apiProvider.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { clientPromise } from "./axios";
22
import type { Client as ApiClient } from "@sparta/utils/openapi/types";
3-
import { logger } from "@sparta/utils";
43

54
/**
65
* Singleton class to provide access to the API client
@@ -31,23 +30,11 @@ export class ApiProvider {
3130
if (this.client) return; // Already initialized
3231

3332
try {
34-
logger.info("Initializing API client");
3533
this.client = await clientPromise;
36-
logger.info("API client initialized successfully");
3734
this.error = null;
3835
} catch (err) {
3936
this.error = err instanceof Error ? err : new Error(String(err));
40-
logger.error(
41-
{
42-
error: this.error,
43-
message: this.error.message,
44-
stack: this.error.stack,
45-
apiUrl:
46-
process.env.VITE_APP_API_URL || "http://localhost:3000",
47-
apiKeyPresent: !!process.env.BACKEND_API_KEY,
48-
},
49-
"ApiProvider: Failed to initialize client"
50-
);
37+
console.error("ApiProvider: Failed to initialize client:", err);
5138
}
5239
}
5340

@@ -57,11 +44,7 @@ export class ApiProvider {
5744
*/
5845
public getClient(): ApiClient {
5946
if (!this.client) {
60-
const error = new Error(
61-
"API client not initialized. Call init() first."
62-
);
63-
logger.error({ error }, "Failed to get API client");
64-
throw error;
47+
throw new Error("API client not initialized. Call init() first.");
6548
}
6649
return this.client;
6750
}

tooling/sparta/packages/discord/src/api/axios.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import { OpenAPIClientAxios } from "openapi-client-axios";
22
import { apiDocs } from "@sparta/utils";
33
import { type Client } from "@sparta/utils/openapi/types";
4-
import { logger } from "@sparta/utils";
5-
6-
// Log environment variables related to API configuration
7-
logger.info(
8-
{
9-
apiUrl: process.env.VITE_APP_API_URL,
10-
nodeEnv: process.env.NODE_ENV,
11-
},
12-
"API client configuration"
13-
);
144

155
const apiInstance = new OpenAPIClientAxios({
166
// @ts-ignore
@@ -23,20 +13,13 @@ const apiInstance = new OpenAPIClientAxios({
2313
Accept: "application/json",
2414
"x-api-key": process.env.BACKEND_API_KEY,
2515
},
26-
// Adding option to allow absolute URLs
27-
allowAbsoluteUrls: true,
2816
},
2917
});
3018

3119
// Initialize and export the promise directly
3220
export const clientPromise = apiInstance
3321
.init<Client>()
3422
.then((client) => {
35-
// Log the configured base URL of the client
36-
logger.info(
37-
{ baseURL: apiInstance.getAxiosInstance().defaults.baseURL },
38-
"API client initialized"
39-
);
4023
return client;
4124
})
4225
.catch((err) => {

tooling/sparta/packages/discord/src/slashCommands/humans/verify.ts

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ export async function handleVerifyCommand(
4545
const client = apiProvider.getClient();
4646

4747
try {
48-
// Log API configuration for debugging
49-
const apiConfig = {
50-
baseUrl:
51-
process.env.VITE_APP_API_URL || "http://localhost:3000",
52-
apiPath: `/api/users/discord/${userId}`,
53-
hasApiKey: !!process.env.BACKEND_API_KEY,
54-
apiKeyLength: process.env.BACKEND_API_KEY?.length,
55-
};
56-
logger.info({ apiConfig }, "API client configuration");
57-
5848
// Check if the user already exists
5949
const userResponse = await client.getUserByDiscordId({
6050
discordUserId: userId,
@@ -145,19 +135,7 @@ export async function handleVerifyCommand(
145135
return;
146136
}
147137

148-
// Ensure the URL has the correct format
149-
let verificationUrl = `${publicFrontendUrl}`;
150-
if (verificationUrl.endsWith("/")) {
151-
verificationUrl = `${verificationUrl}?verificationId=${verificationId}`;
152-
} else {
153-
verificationUrl = `${verificationUrl}/?verificationId=${verificationId}`;
154-
}
155-
156-
// Log the verification URL (strip the ID for security)
157-
logger.info(
158-
{ verificationUrlBase: verificationUrl.split("?")[0] },
159-
"Created verification URL"
160-
);
138+
const verificationUrl = `${publicFrontendUrl}/?verificationId=${verificationId}`;
161139

162140
// Create a button with the verification link
163141
const verifyButton = new ButtonBuilder()
@@ -181,22 +159,7 @@ export async function handleVerifyCommand(
181159
"Created verification session for user"
182160
);
183161
} catch (error: any) {
184-
logger.error(
185-
{
186-
error,
187-
errorMessage: error.message,
188-
stack: error.stack,
189-
code: error.code,
190-
status: error.status,
191-
config: error.config,
192-
baseUrl:
193-
process.env.VITE_APP_API_URL || "http://localhost:3000",
194-
backendApiKey: process.env.BACKEND_API_KEY
195-
? "present"
196-
: "missing",
197-
},
198-
"Error handling passport verify command"
199-
);
162+
logger.error(error, "Error handling passport verify command");
200163

201164
await interaction.reply({
202165
content:
@@ -205,22 +168,7 @@ export async function handleVerifyCommand(
205168
});
206169
}
207170
} catch (error: any) {
208-
logger.error(
209-
{
210-
error,
211-
errorMessage: error.message,
212-
stack: error.stack,
213-
code: error.code,
214-
status: error.status,
215-
config: error.config,
216-
baseUrl:
217-
process.env.VITE_APP_API_URL || "http://localhost:3000",
218-
backendApiKey: process.env.BACKEND_API_KEY
219-
? "present"
220-
: "missing",
221-
},
222-
"Error handling passport verify command"
223-
);
171+
logger.error(error, "Error handling passport verify command");
224172

225173
await interaction.reply({
226174
content:

tooling/sparta/terraform/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ resource "aws_ecs_task_definition" "sparta_api" {
492492
{ name = "L1_CHAIN_ID", value = var.l1_chain_id },
493493
{ name = "LOG_LEVEL", value = var.log_level },
494494
{ name = "LOG_PRETTY_PRINT", value = var.log_pretty_print ? "true" : "false" },
495-
{ name = "VITE_APP_API_URL", value = "http://${aws_lb.sparta_alb.dns_name}/api" },
495+
{ name = "VITE_APP_API_URL", value = "http://${aws_lb.sparta_alb.dns_name}" },
496496
{ name = "CORS_ALLOWED_ORIGINS", value = "http://${aws_lb.sparta_alb.dns_name}" },
497497
{ name = "USERS_TABLE_NAME", value = aws_dynamodb_table.sparta_users.name },
498498
{ name = "NODE_OPERATORS_TABLE_NAME", value = aws_dynamodb_table.sparta_node_operators.name }

0 commit comments

Comments
 (0)