feat: display API errors
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c026ed4c6f
commit
89d2e1b9b3
@ -6,6 +6,7 @@ import GithubRepository from './components/GitHub/GithubRepository.vue';
|
|||||||
import ApiLoader from './components/ApiLoader.vue';
|
import ApiLoader from './components/ApiLoader.vue';
|
||||||
import Loader from './components/Loader.vue';
|
import Loader from './components/Loader.vue';
|
||||||
import Cache from './components/Cache.vue';
|
import Cache from './components/Cache.vue';
|
||||||
|
import Error from './components/Error.vue';
|
||||||
import Icon from './components/Icon.vue';
|
import Icon from './components/Icon.vue';
|
||||||
|
|
||||||
export default defineClientConfig({
|
export default defineClientConfig({
|
||||||
@ -17,6 +18,7 @@ export default defineClientConfig({
|
|||||||
app.component('ApiLoader', ApiLoader);
|
app.component('ApiLoader', ApiLoader);
|
||||||
app.component('Loader', Loader);
|
app.component('Loader', Loader);
|
||||||
app.component('Cache', Cache);
|
app.component('Cache', Cache);
|
||||||
|
app.component('Error', Error);
|
||||||
app.component('Icon', Icon);
|
app.component('Icon', Icon);
|
||||||
},
|
},
|
||||||
setup() {},
|
setup() {},
|
||||||
|
@ -8,15 +8,16 @@
|
|||||||
<slot v-if="loading" name="loader">
|
<slot v-if="loading" name="loader">
|
||||||
<Loader />
|
<Loader />
|
||||||
</slot>
|
</slot>
|
||||||
<slot v-else-if="error" name="error"></slot>
|
<slot v-else-if="error" name="error">
|
||||||
<slot v-else>
|
<Error :url="props.url" />
|
||||||
{{ error }}
|
|
||||||
</slot>
|
</slot>
|
||||||
|
<slot v-else> </slot>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Cache from './Cache.vue';
|
import Cache from './Cache.vue';
|
||||||
import Loader from './Loader.vue';
|
import Loader from './Loader.vue';
|
||||||
|
import Error from './Error.vue';
|
||||||
|
|
||||||
import { Ref, ref } from 'vue';
|
import { Ref, ref } from 'vue';
|
||||||
import { Observable, catchError, switchMap, throwError } from 'rxjs';
|
import { Observable, catchError, switchMap, throwError } from 'rxjs';
|
||||||
@ -42,9 +43,9 @@ const loading: Ref<boolean> = ref(true);
|
|||||||
const fetchData = (): Observable<any> => {
|
const fetchData = (): Observable<any> => {
|
||||||
return fromFetch(props.url).pipe(
|
return fromFetch(props.url).pipe(
|
||||||
switchMap((response: Response) => response.json()),
|
switchMap((response: Response) => response.json()),
|
||||||
catchError((error: Error) => {
|
catchError((errorResponse: Error) => {
|
||||||
console.error(error);
|
error.value = errorResponse;
|
||||||
return throwError(() => new Error(error.message));
|
return Error;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -62,5 +63,3 @@ const processCachedData = (data: Observable<any>) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less"></style>
|
|
||||||
|
26
content/.vuepress/components/Error.vue
Normal file
26
content/.vuepress/components/Error.vue
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<template>
|
||||||
|
<div class="error rounded-corners card-width">
|
||||||
|
<p>API call to {{ props.url }} failed</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps({
|
||||||
|
url: {
|
||||||
|
required: true,
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
@import 'node_modules/nord/src/lesscss/nord.less';
|
||||||
|
@import '../styles/classes.less';
|
||||||
|
|
||||||
|
.error {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
background: @nord11;
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,5 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="githubRepo flex-col flex-space-between gap-1rem rounded-corners">
|
<div
|
||||||
|
class="githubRepo flex-col flex-space-between gap-1rem rounded-corners card-width"
|
||||||
|
>
|
||||||
<ApiLoader
|
<ApiLoader
|
||||||
:cache-name="repoName()"
|
:cache-name="repoName()"
|
||||||
:url="fetchUrl"
|
:url="fetchUrl"
|
||||||
@ -51,7 +53,6 @@ const repository: Ref<GithubRepo> = ref(null);
|
|||||||
@import '../../styles/classes.less';
|
@import '../../styles/classes.less';
|
||||||
|
|
||||||
.githubRepo {
|
.githubRepo {
|
||||||
max-width: 35rem;
|
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
background-color: @nord4;
|
background-color: @nord4;
|
||||||
align-self: auto;
|
align-self: auto;
|
||||||
|
@ -50,3 +50,7 @@ each(@flex-justifications, {
|
|||||||
.center {
|
.center {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card-width {
|
||||||
|
max-width: 35rem;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user