Skip to content

Commit b0d927c

Browse files
committed
showing proper OBP error message instead of squashing them
1 parent 6d1aac9 commit b0d927c

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

server/app.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ let sessionObject = {
9898
store: redisStore,
9999
secret: process.env.VITE_OPB_SERVER_SESSION_PASSWORD,
100100
resave: false,
101-
saveUninitialized: true,
101+
saveUninitialized: false, // Don't save empty sessions (better for authenticated apps)
102102
cookie: {
103103
httpOnly: true,
104104
secure: false,
105-
maxAge: 300 * 1000 // 5 minutes in milliseconds
105+
maxAge: process.env.VITE_SESSION_MAX_AGE
106+
? parseInt(process.env.VITE_SESSION_MAX_AGE) * 1000
107+
: 60 * 60 * 1000 // Default: 1 hour in milliseconds (value in env should be in seconds)
106108
}
107109
}
108110
if (app.get('env') === 'production') {

server/controllers/RequestController.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ export class OBPController {
7474
const data = request.body
7575
const oauthConfig = session['clientConfig']
7676

77+
// Debug logging to diagnose authentication issues
78+
console.log('RequestController.create - Debug Info:')
79+
console.log(' Path:', path)
80+
console.log(' Session exists:', !!session)
81+
console.log(' Session keys:', session ? Object.keys(session) : 'N/A')
82+
console.log(' clientConfig exists:', !!oauthConfig)
83+
console.log(' oauth2 exists:', oauthConfig?.oauth2 ? 'YES' : 'NO')
84+
console.log(' accessToken exists:', oauthConfig?.oauth2?.accessToken ? 'YES' : 'NO')
85+
console.log(' oauth2_user exists:', session?.oauth2_user ? 'YES' : 'NO')
86+
7787
try {
7888
const result = await this.obpClientService.create(path, data, oauthConfig)
7989
return response.json(result)

src/components/Preview.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ const submit = async (form: FormInstance, fn: () => void) => {
174174
}
175175
const highlightCode = (json) => {
176176
if (json.error) {
177-
successResponseBody.value = json.error.message
177+
// Display the full OBP error object with proper formatting
178+
successResponseBody.value = hljs.lineNumbersValue(
179+
hljs.highlightAuto(JSON.stringify(json.error, null, 4), ['JSON']).value
180+
)
178181
} else if (json) {
179182
successResponseBody.value = hljs.lineNumbersValue(
180183
hljs.highlightAuto(JSON.stringify(json, null, 4), ['JSON']).value

src/obp/index.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ export async function isServerUp(): Promise<boolean> {
4545
export async function get(path: string): Promise<any> {
4646
try {
4747
return (await superagent.get(`/api/get?path=${path}`)).body
48-
} catch (error) {
48+
} catch (error: any) {
4949
console.log(error)
50+
// Extract the full OBP error message from the response body
51+
if (error.response && error.response.body) {
52+
return { error: error.response.body }
53+
}
5054
return { error }
5155
}
5256
}
@@ -70,8 +74,12 @@ export async function create(path: string, body?: any): Promise<any> {
7074
}
7175
}
7276
return (await request).body
73-
} catch (error) {
77+
} catch (error: any) {
7478
console.log(error)
79+
// Extract the full OBP error message from the response body
80+
if (error.response && error.response.body) {
81+
return { error: error.response.body }
82+
}
7583
return { error }
7684
}
7785
}
@@ -95,26 +103,38 @@ export async function update(path: string, body?: any): Promise<any> {
95103
}
96104
}
97105
return (await request).body
98-
} catch (error) {
106+
} catch (error: any) {
99107
console.log(error)
108+
// Extract the full OBP error message from the response body
109+
if (error.response && error.response.body) {
110+
return { error: error.response.body }
111+
}
100112
return { error }
101113
}
102114
}
103115

104116
export async function discard(path: string): Promise<any> {
105117
try {
106118
return (await superagent.delete(`/api/delete?path=${path}`)).body
107-
} catch (error) {
119+
} catch (error: any) {
108120
console.log(error)
121+
// Extract the full OBP error message from the response body
122+
if (error.response && error.response.body) {
123+
return { error: error.response.body }
124+
}
109125
return { error }
110126
}
111127
}
112128

113129
export async function getCurrentUser(): Promise<any> {
114130
try {
115131
return (await superagent.get(`/api/user/current`)).body
116-
} catch (error) {
132+
} catch (error: any) {
117133
console.log(error)
134+
// Extract the full OBP error message from the response body
135+
if (error.response && error.response.body) {
136+
return { error: error.response.body }
137+
}
118138
return { error }
119139
}
120140
}

0 commit comments

Comments
 (0)