Fixes #2998 the templates API call will no longer fail if no internet, will simply return an empty array.

This commit is contained in:
mike12345567 2021-10-14 14:18:41 +01:00
parent 2635c055b7
commit c5ed99939c
3 changed files with 24 additions and 7 deletions

View File

@ -150,7 +150,6 @@
showCancelButton={false} showCancelButton={false}
showCloseIcon={false} showCloseIcon={false}
> >
<Body size="M">Select a template below, or start from scratch.</Body>
<TemplateList <TemplateList
onSelect={selected => { onSelect={selected => {
if (!selected) { if (!selected) {

View File

@ -1,5 +1,5 @@
<script> <script>
import { Heading, Layout, Icon } from "@budibase/bbui" import { Heading, Layout, Icon, Body } from "@budibase/bbui"
import Spinner from "components/common/Spinner.svelte" import Spinner from "components/common/Spinner.svelte"
import api from "builderStore/api" import api from "builderStore/api"
@ -7,6 +7,7 @@
async function fetchTemplates() { async function fetchTemplates() {
const response = await api.get("/api/templates?type=app") const response = await api.get("/api/templates?type=app")
console.log("Responded")
return await response.json() return await response.json()
} }
@ -19,6 +20,11 @@
<Spinner size="30" /> <Spinner size="30" />
</div> </div>
{:then templates} {: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"> <div class="templates">
{#each templates as template} {#each templates as template}
<div class="template" on:click={() => onSelect(template)}> <div class="template" on:click={() => onSelect(template)}>

View File

@ -7,11 +7,23 @@ const DEFAULT_TEMPLATES_BUCKET =
exports.fetch = async function (ctx) { exports.fetch = async function (ctx) {
const { type = "app" } = ctx.query const { type = "app" } = ctx.query
const response = await fetch( let response,
`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json` error = false
) try {
const json = await response.json() response = await fetch(`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`)
ctx.body = Object.values(json.templates[type]) 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 // can't currently test this, have to ignore from coverage