You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every fractal server REST endpoint that the client application support is listed within a file in `src/server/api/v1`.
88
-
Here requests are grouped by contexts as `auth_api`, `monitoring_api`, [...].
84
+
To avoid duplicating the logic of each fractal-server endpoint and simplify the error handling, a special Svelte route has been setup to act like a transparent proxy: `src/routes/api/[...path]/+server.js`. This is one of the suggested way to handle a different backend [according to Svelte Kit FAQ](https://kit.svelte.dev/docs/faq#how-do-i-use-x-with-sveltekit-how-do-i-use-a-different-backend-api-server).
89
85
90
-
### An example
86
+
So, by default, the AJAX calls performed by the front-end have exactly the same path and payload of the fractal-server API, but are sent to the Node.js Svelte back-end.
91
87
92
-
For instance, considering the code at `src/lib/server/api/v1/auth_api.js:5`:
88
+
Other than the AJAX calls, there are also some calls to fractal-server API done by Svelte SSR, while generating the HTML page. These requests are defined in files under `src/lib/server/api/v1`. Here requests are grouped by contexts as `auth_api`, `monitoring_api`, [...].
89
+
90
+
### An example using actions
91
+
92
+
The login is still using the Svelte action approach, in which we have to extract the data from a formData object and then use it to build a JSON payload to be forwarded to fractal-server.
93
+
94
+
Consider the code at `src/lib/server/api/v1/auth_api.js:5`:
93
95
94
96
```javascript
95
97
/**
@@ -241,3 +243,37 @@ _Stores_ are modules that export svelte store objects that are used by component
241
243
application.
242
244
> Note that stores are currently not well-organized or used due to the youth of the client.
243
245
246
+
## Error handling
247
+
248
+
The errors received from fractal-server are displayed in error modals without changing the content of their messages. The `displayStandardErrorAlert()` function can be used to easily display an error message alert in a div having a specific id. This function returns a `StandardErrorAlert` object that can be stored in a variable and then used to hide previous error messages calling its `hide()` method.
249
+
250
+
Here an example:
251
+
252
+
```javascript
253
+
asyncfunctionmyFunction() {
254
+
// remove previous error
255
+
if (errorAlert) {
256
+
errorAlert.hide();
257
+
}
258
+
259
+
constresponse=awaitfetch(`/api/v1/something`);
260
+
if (response.ok) {
261
+
// do something with the result
262
+
} else {
263
+
consterror=awaitresponse.json();
264
+
// add error alert inside the element having 'errorElement' as id
When the displaying of the error alert should be handled by the caller function it is possible to throw an `AlertError` that has to be caught by the caller in order to display the message.
271
+
272
+
Errors happening during SSR should be considered fatal and propagated using the `responseError()` utility function:
0 commit comments