Coder Social home page Coder Social logo

Comments (4)

soedirgo avatar soedirgo commented on July 27, 2024 2

Hey @themixednuts, you can also do this by wrapping the call in an async function:

export const load: PageServerLoad = async ({ locals: { safeGetSession, supabase }, params: { id } }) => {
	const { session } = await safeGetSession()

	if (!session?.user.id) {
		throw redirect(303, '/login')
	}

       const profile = (async () => await supabase.from('profiles').select().eq('id', id))()
      
      // this is not part of the issue but show cases how SvelteKit wants you to handle errors on streams, but can't do this since there is no catch method. throwOnError() doesn't provide it with a catch() method either. 

       profile.catch(e => console.log(e))

	return {
		profile
	}
}

from supabase-js.

encima avatar encima commented on July 27, 2024

Hi @themixednuts
I am not super familiar with Sveltekit so you might need to educate me a bit!

By stream, you mean streamed promise? What stops you from streaming the promise and catching on Svelte's side with {:catch}? I might be wrong but I thought that was the recommended practice

from supabase-js.

themixednuts avatar themixednuts commented on July 27, 2024

Hi @themixednuts I am not super familiar with Sveltekit so you might need to educate me a bit!

By stream, you mean streamed promise? What stops you from streaming the promise and catching on Svelte's side with {:catch}? I might be wrong but I thought that was the recommended practice

All good! I think the docs will explain the best here https://kit.svelte.dev/docs/load#streaming-with-promises.

In the code side, sveltekit checks for a .catch() on the promise, and since there is none it throws an error. So {:catch} wouldn't even be possible even so.

from supabase-js.

encima avatar encima commented on July 27, 2024

Thanks for the pointer, so it looks like the call you make returns a PromiseLike from the PostgrestBuilder object that does not implement catch (see here)

What you could do is map the throwOnError to catch for Svelte to pick up but possibly others have different ideas?

from supabase-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.