Skip to content

Commit

Permalink
Merge pull request #334 from ckeditor/ck/print-cdn-errors-in-console
Browse files Browse the repository at this point in the history
Feat: Log cloud fetch errors to console.
  • Loading branch information
Mati365 authored Nov 28, 2024
2 parents 1c6dcf0 + ee87969 commit 8ce672b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 1 addition & 7 deletions demos/editor-cdn/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</template>

<script setup lang="ts">
import { ref, reactive, computed, effect } from 'vue';
import { ref, reactive, computed } from 'vue';
import useCKEditorCloud from '../../src/useCKEditorCloud.js';
import type { EventInfo, ClassicEditor } from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';
Expand All @@ -46,12 +46,6 @@ const cloud = useCKEditorCloud( {
version: '43.0.0'
} );
effect( () => {
if ( cloud.error.value ) {
console.error( cloud.error.value );
}
} );
const TestEditor = computed<typeof ClassicEditor | null>( () => {
if ( !cloud.data.value ) {
return null;
Expand Down
2 changes: 2 additions & 0 deletions src/composables/useAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const useAsync = <R>(
data.value = result;
}
} catch ( err: any ) {
console.error( err );

if ( !shouldDiscardQuery() ) {
error.value = err;
}
Expand Down
16 changes: 15 additions & 1 deletion tests/composables/useAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/

import { it, describe, expect } from 'vitest';
import { it, vi, describe, expect } from 'vitest';
import { ref } from 'vue';
import { flushPromises } from '@vue/test-utils';

Expand Down Expand Up @@ -42,6 +42,20 @@ describe( 'useAsync', () => {
expect( data.value ).toBe( null );
} );

it( 'should print errors in console if the async function throws an error', async () => {
const errorInstance = new Error( 'test' );
const consoleSpy = vi.spyOn( console, 'error' );

useAsync( async () => {
throw errorInstance;
} );

await flushPromises();

expect( consoleSpy ).toHaveBeenCalledWith( errorInstance );
consoleSpy.mockRestore();
} );

it( 'should re-run async function on change ref inside async function', async () => {
const refValue = ref( 0 );
const { data } = useAsync( async () => refValue.value );
Expand Down

0 comments on commit 8ce672b

Please sign in to comment.