Fix 502 errors on container restart and expand API authentication
- Handle 502 Gateway Timeout errors by clearing invalid sessions - Add graceful session validation failure handling in fetch-thread API - Expand x-tag authentication to accept additional valid token - Add debug logging to berth-related API endpoints - Document the 502 error fix in email system documentation
This commit is contained in:
parent
1866dfd010
commit
48cee6f849
|
|
@ -215,6 +215,17 @@ const loadEmails = async () => {
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Failed to load emails:', error);
|
console.error('Failed to load emails:', error);
|
||||||
|
|
||||||
|
// Handle 502 Gateway Timeout - session is likely invalid after container restart
|
||||||
|
if (error.statusCode === 502 || error.status === 502) {
|
||||||
|
console.log('Got 502 error, clearing invalid session');
|
||||||
|
// Clear the invalid session
|
||||||
|
sessionStorage.removeItem('emailSessionId');
|
||||||
|
// Don't show error toast, just reset to no emails
|
||||||
|
threads.value = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (error.data?.statusMessage?.includes('Email credentials not found')) {
|
if (error.data?.statusMessage?.includes('Email credentials not found')) {
|
||||||
// Don't show error, parent component should handle reconnection
|
// Don't show error, parent component should handle reconnection
|
||||||
threads.value = [];
|
threads.value = [];
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,14 @@
|
||||||
- Changed `sendEmail` to `true` to ensure recipients receive signing emails
|
- Changed `sendEmail` to `true` to ensure recipients receive signing emails
|
||||||
- Correctly extract signing URLs from the response
|
- Correctly extract signing URLs from the response
|
||||||
|
|
||||||
|
### 8. 502 Bad Gateway on Container Restart
|
||||||
|
- **Problem**: Getting 502 errors when refreshing after container restart
|
||||||
|
- **Solution**:
|
||||||
|
- Added better session validation in `fetch-thread` API
|
||||||
|
- Added try-catch for decryption failures (session invalid after restart)
|
||||||
|
- Client-side now detects 502 errors and clears invalid sessions
|
||||||
|
- No error toast shown - just resets to empty email state
|
||||||
|
|
||||||
## Required Environment Variables
|
## Required Environment Variables
|
||||||
|
|
||||||
Make sure these are set in your `.env` file:
|
Make sure these are set in your `.env` file:
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,22 @@ export default defineEventHandler(async (event) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrypt credentials
|
// Decrypt credentials
|
||||||
const { email: userEmail, password } = decryptCredentials(encryptedCredentials);
|
let userEmail: string;
|
||||||
|
let password: string;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const decrypted = decryptCredentials(encryptedCredentials);
|
||||||
|
userEmail = decrypted.email;
|
||||||
|
password = decrypted.password;
|
||||||
|
} catch (decryptError) {
|
||||||
|
console.error('Failed to decrypt credentials - session may be invalid after restart:', decryptError);
|
||||||
|
// Return empty results for invalid session
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
emails: [],
|
||||||
|
threads: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// First, get emails from MinIO cache if available
|
// First, get emails from MinIO cache if available
|
||||||
const cachedEmails: EmailMessage[] = [];
|
const cachedEmails: EmailMessage[] = [];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||||
|
console.log('[link-berth-recommendations] Request received with x-tag:', xTagHeader);
|
||||||
|
|
||||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||||
|
console.error('[link-berth-recommendations] Authentication failed - invalid x-tag:', xTagHeader);
|
||||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,48 @@
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||||
|
console.log('[link-berths] Request received with x-tag:', xTagHeader);
|
||||||
|
|
||||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||||
|
console.error('[link-berths] Authentication failed - invalid x-tag:', xTagHeader);
|
||||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await readBody(event);
|
try {
|
||||||
const { interestId, berthIds } = body;
|
const body = await readBody(event);
|
||||||
|
const { interestId, berthIds } = body;
|
||||||
|
console.log('[link-berths] Request body:', { interestId, berthIds });
|
||||||
|
|
||||||
if (!interestId || !berthIds || !Array.isArray(berthIds)) {
|
if (!interestId || !berthIds || !Array.isArray(berthIds)) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 400,
|
statusCode: 400,
|
||||||
statusMessage: "interestId and berthIds array are required"
|
statusMessage: "interestId and berthIds array are required"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = getNocoDbConfiguration();
|
const config = getNocoDbConfiguration();
|
||||||
const interestsTableId = "mbs9hjauug4eseo";
|
const interestsTableId = "mbs9hjauug4eseo";
|
||||||
const berthsLinkFieldId = "cj7v7bb9pa5eyo3"; // Berths field
|
const berthsLinkFieldId = "cj7v7bb9pa5eyo3"; // Berths field
|
||||||
|
|
||||||
// Format the berth IDs for the API
|
// Format the berth IDs for the API
|
||||||
const berthRecords = berthIds.map(id => ({ Id: id }));
|
const berthRecords = berthIds.map(id => ({ Id: id }));
|
||||||
|
console.log('[link-berths] Berth records to link:', berthRecords);
|
||||||
const result = await $fetch(
|
|
||||||
`${config.url}/api/v2/tables/${interestsTableId}/links/${berthsLinkFieldId}/records/${interestId}`,
|
const url = `${config.url}/api/v2/tables/${interestsTableId}/links/${berthsLinkFieldId}/records/${interestId}`;
|
||||||
{
|
console.log('[link-berths] URL:', url);
|
||||||
|
|
||||||
|
const result = await $fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"xc-token": config.token,
|
"xc-token": config.token,
|
||||||
},
|
},
|
||||||
body: berthRecords,
|
body: berthRecords,
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
console.log('[link-berths] Successfully linked berths to interest:', interestId);
|
||||||
return result;
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[link-berths] Error occurred:', error);
|
||||||
|
console.error('[link-berths] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||||
|
console.log('[unlink-berth-recommendations] Request received with x-tag:', xTagHeader);
|
||||||
|
|
||||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||||
|
console.error('[unlink-berth-recommendations] Authentication failed - invalid x-tag:', xTagHeader);
|
||||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||||
|
console.log('[unlink-berths] Request received with x-tag:', xTagHeader);
|
||||||
|
|
||||||
if (!xTagHeader || xTagHeader !== "094ut234") {
|
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||||
|
console.error('[unlink-berths] Authentication failed - invalid x-tag:', xTagHeader);
|
||||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,19 @@ export const updateInterest = async (id: string, data: Partial<Interest>) => {
|
||||||
});
|
});
|
||||||
console.log('[nocodb.updateInterest] Update successful for ID:', id);
|
console.log('[nocodb.updateInterest] Update successful for ID:', id);
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('[nocodb.updateInterest] Update failed:', error);
|
console.error('[nocodb.updateInterest] Update failed:', error);
|
||||||
console.error('[nocodb.updateInterest] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
console.error('[nocodb.updateInterest] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
||||||
|
|
||||||
|
// If it's a 404 error for a newly created record, provide more context
|
||||||
|
if (error.statusCode === 404 || error.status === 404) {
|
||||||
|
console.error('[nocodb.updateInterest] 404 Error - Record not found. This might happen if:');
|
||||||
|
console.error('1. The record ID is incorrect');
|
||||||
|
console.error('2. The record was just created and is not yet available');
|
||||||
|
console.error('3. The record was deleted');
|
||||||
|
console.error('Attempted URL:', url);
|
||||||
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue