showing proper OBP error message instead of squashing them

This commit is contained in:
simonredfern 2025-12-03 21:50:56 +01:00
parent 6d1aac927e
commit b0d927c1e1
4 changed files with 43 additions and 8 deletions

View File

@ -98,11 +98,13 @@ let sessionObject = {
store: redisStore,
secret: process.env.VITE_OPB_SERVER_SESSION_PASSWORD,
resave: false,
saveUninitialized: true,
saveUninitialized: false, // Don't save empty sessions (better for authenticated apps)
cookie: {
httpOnly: true,
secure: false,
maxAge: 300 * 1000 // 5 minutes in milliseconds
maxAge: process.env.VITE_SESSION_MAX_AGE
? parseInt(process.env.VITE_SESSION_MAX_AGE) * 1000
: 60 * 60 * 1000 // Default: 1 hour in milliseconds (value in env should be in seconds)
}
}
if (app.get('env') === 'production') {

View File

@ -74,6 +74,16 @@ export class OBPController {
const data = request.body
const oauthConfig = session['clientConfig']
// Debug logging to diagnose authentication issues
console.log('RequestController.create - Debug Info:')
console.log(' Path:', path)
console.log(' Session exists:', !!session)
console.log(' Session keys:', session ? Object.keys(session) : 'N/A')
console.log(' clientConfig exists:', !!oauthConfig)
console.log(' oauth2 exists:', oauthConfig?.oauth2 ? 'YES' : 'NO')
console.log(' accessToken exists:', oauthConfig?.oauth2?.accessToken ? 'YES' : 'NO')
console.log(' oauth2_user exists:', session?.oauth2_user ? 'YES' : 'NO')
try {
const result = await this.obpClientService.create(path, data, oauthConfig)
return response.json(result)

View File

@ -174,7 +174,10 @@ const submit = async (form: FormInstance, fn: () => void) => {
}
const highlightCode = (json) => {
if (json.error) {
successResponseBody.value = json.error.message
// Display the full OBP error object with proper formatting
successResponseBody.value = hljs.lineNumbersValue(
hljs.highlightAuto(JSON.stringify(json.error, null, 4), ['JSON']).value
)
} else if (json) {
successResponseBody.value = hljs.lineNumbersValue(
hljs.highlightAuto(JSON.stringify(json, null, 4), ['JSON']).value

View File

@ -45,8 +45,12 @@ export async function isServerUp(): Promise<boolean> {
export async function get(path: string): Promise<any> {
try {
return (await superagent.get(`/api/get?path=${path}`)).body
} catch (error) {
} catch (error: any) {
console.log(error)
// Extract the full OBP error message from the response body
if (error.response && error.response.body) {
return { error: error.response.body }
}
return { error }
}
}
@ -70,8 +74,12 @@ export async function create(path: string, body?: any): Promise<any> {
}
}
return (await request).body
} catch (error) {
} catch (error: any) {
console.log(error)
// Extract the full OBP error message from the response body
if (error.response && error.response.body) {
return { error: error.response.body }
}
return { error }
}
}
@ -95,8 +103,12 @@ export async function update(path: string, body?: any): Promise<any> {
}
}
return (await request).body
} catch (error) {
} catch (error: any) {
console.log(error)
// Extract the full OBP error message from the response body
if (error.response && error.response.body) {
return { error: error.response.body }
}
return { error }
}
}
@ -104,8 +116,12 @@ export async function update(path: string, body?: any): Promise<any> {
export async function discard(path: string): Promise<any> {
try {
return (await superagent.delete(`/api/delete?path=${path}`)).body
} catch (error) {
} catch (error: any) {
console.log(error)
// Extract the full OBP error message from the response body
if (error.response && error.response.body) {
return { error: error.response.body }
}
return { error }
}
}
@ -113,8 +129,12 @@ export async function discard(path: string): Promise<any> {
export async function getCurrentUser(): Promise<any> {
try {
return (await superagent.get(`/api/user/current`)).body
} catch (error) {
} catch (error: any) {
console.log(error)
// Extract the full OBP error message from the response body
if (error.response && error.response.body) {
return { error: error.response.body }
}
return { error }
}
}