Skip to content

Commit

Permalink
better error message in gitlab connector, better detection of website…
Browse files Browse the repository at this point in the history
… loaded
  • Loading branch information
lexoyo committed May 29, 2024
1 parent 5481117 commit f599f97
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
4 changes: 1 addition & 3 deletions src/ts/client/grapesjs/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export const storagePlugin = (editor) => {
try {
editor.StorageManager.setAutosave(false)
const data = await editor.Storage.load(options)
editor.on('canvas:frame:load', ({ window }) => {
// This needs time for grapesjs to change the dom
// Otherwise a save is triggered on load
editor.once('canvas:frame:load', ({ window }) => {
editor.editor.set('changesCount', 0)
editor.UndoManager.clear()
editor.StorageManager.setAutosave(true)
Expand Down
10 changes: 1 addition & 9 deletions src/ts/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export async function start(options = {}): Promise<void> {
await config.addDefaultPlugins()

// Load the site
editor.StorageManager.setAutosave(false)
try {
await editor.load(null)
} catch(e) {
Expand All @@ -89,18 +88,11 @@ export async function start(options = {}): Promise<void> {
// Will display an error message, see in storage.ts
}
} finally {
setTimeout(() => {
editor.once('canvas:frame:load', ({ window }) => {
// This needs time for the loader to be hidden
document.querySelector('.silex-loader').classList.add('silex-dialog-hide')
document.querySelector('#gjs').classList.remove('silex-dialog-hide')
config.emit(ClientEvent.STARTUP_END, { editor, config })
setTimeout(() => {
// This needs time for grapesjs to change the dom
// Otherwise a save is triggered on load
editor.editor.set('changesCount', 0)
editor.UndoManager.clear()
editor.StorageManager.setAutosave(true)
})
})
}
}
22 changes: 14 additions & 8 deletions src/ts/plugins/server/GitlabConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,20 @@ export default class GitlabConnector implements StorageConnector {
console.error('Gitlab API error (4) - GET request with body', {url, method, body, params})
}
// With or without body
const response = await fetch(url, body && method !== 'GET' ? {
method,
headers,
body: body ? JSON.stringify(body) : undefined
} : {
method,
headers,
})
let response
try {
response = await fetch(url, body && method !== 'GET' ? {
method,
headers,
body: body ? JSON.stringify(body) : undefined
} : {
method,
headers,
})
} catch (e) {
console.error('Gitlab API error (0)', e)
throw new ApiError(`Gitlab API error (0): ${e.message} ${e.code} ${e.name} ${e.type}`, 500)
}
let json: { message: string, error: string } | any
// Handle the case when the server returns an non-JSON response (e.g. 400 Bad Request)
const text = await response.text()
Expand Down
2 changes: 1 addition & 1 deletion src/ts/server/api/connectorApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function routeUser(req: Request, res: Response) {
res.json(user as ApiConnectorUserResponse)
} catch (error) {
console.error('Error in the user request', error, error.code)
res.status(validateStatus(error?.code ?? error?.httpStatusCode, 500)).json({
res.status(validateStatus(error.code ?? error.httpStatusCode, 500)).json({
error: true,
message: error.message,
} as ApiResponseError)
Expand Down

0 comments on commit f599f97

Please sign in to comment.