Fixes #2998 the templates API call will no longer fail if no internet, will simply return an empty array.
This commit is contained in:
parent
54fff6db18
commit
eb25e81072
|
@ -150,7 +150,6 @@
|
|||
showCancelButton={false}
|
||||
showCloseIcon={false}
|
||||
>
|
||||
<Body size="M">Select a template below, or start from scratch.</Body>
|
||||
<TemplateList
|
||||
onSelect={selected => {
|
||||
if (!selected) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
import { Heading, Layout, Icon } from "@budibase/bbui"
|
||||
import { Heading, Layout, Icon, Body } from "@budibase/bbui"
|
||||
import Spinner from "components/common/Spinner.svelte"
|
||||
import api from "builderStore/api"
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
|||
|
||||
async function fetchTemplates() {
|
||||
const response = await api.get("/api/templates?type=app")
|
||||
console.log("Responded")
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
|
@ -19,6 +20,11 @@
|
|||
<Spinner size="30" />
|
||||
</div>
|
||||
{:then templates}
|
||||
{#if templates?.length > 0}
|
||||
<Body size="M">Select a template below, or start from scratch.</Body>
|
||||
{:else}
|
||||
<Body size="M">Start your app from scratch below.</Body>
|
||||
{/if}
|
||||
<div class="templates">
|
||||
{#each templates as template}
|
||||
<div class="template" on:click={() => onSelect(template)}>
|
||||
|
|
|
@ -7,11 +7,23 @@ const DEFAULT_TEMPLATES_BUCKET =
|
|||
|
||||
exports.fetch = async function (ctx) {
|
||||
const { type = "app" } = ctx.query
|
||||
const response = await fetch(
|
||||
`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`
|
||||
)
|
||||
const json = await response.json()
|
||||
ctx.body = Object.values(json.templates[type])
|
||||
let response,
|
||||
error = false
|
||||
try {
|
||||
response = await fetch(`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`)
|
||||
if (response.status !== 200) {
|
||||
error = true
|
||||
}
|
||||
} catch (err) {
|
||||
error = true
|
||||
}
|
||||
// if there is an error, simply return no templates
|
||||
if (!error && response) {
|
||||
const json = await response.json()
|
||||
ctx.body = Object.values(json.templates[type])
|
||||
} else {
|
||||
ctx.body = []
|
||||
}
|
||||
}
|
||||
|
||||
// can't currently test this, have to ignore from coverage
|
||||
|
|
Loading…
Reference in New Issue