mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Add http error handling
Because we are using fetch here to manually request turbo stream we have to handle errors ourselves.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "stimulus";
|
||||
import showHttpError from "../../webpacker/js/services/show_http_error";
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["rule", "ruleCustomerTag"];
|
||||
@@ -29,11 +30,17 @@ export default class extends Controller {
|
||||
Accept: "text/vnd.turbo-stream.html",
|
||||
},
|
||||
})
|
||||
.then((r) => r.text())
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
showHttpError(response.status);
|
||||
throw response;
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then((html) => {
|
||||
Turbo.renderStreamMessage(html);
|
||||
this.indexValue = parseInt(index) + 1;
|
||||
})
|
||||
.catch((error) => console.warn(error));
|
||||
.catch((error) => console.error(error));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "stimulus";
|
||||
import showHttpError from "../../webpacker/js/services/show_http_error";
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["index", "customerRuleIndex"];
|
||||
@@ -19,11 +20,17 @@ export default class extends Controller {
|
||||
Accept: "text/vnd.turbo-stream.html",
|
||||
},
|
||||
})
|
||||
.then((r) => r.text())
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
showHttpError(response.status);
|
||||
throw response;
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then((html) => {
|
||||
Turbo.renderStreamMessage(html);
|
||||
this.indexTarget.value = parseInt(index) + 1;
|
||||
})
|
||||
.catch((error) => console.warn(error));
|
||||
.catch((error) => console.error(error));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user