Skip to content

Conversation

@dshukertjr
Copy link
Member

What kind of change does this PR introduce?

Adds support to emulate errors.

What is the current behavior?

There are no way to emulate errors.

What is the new behavior?

You can emulate PostgrestExceptions with the postgrestExceptionTrigger parameter.

mockHttpClient = MockSupabaseHttpClient(
  postgrestExceptionTrigger: (schema, table, data, type) {
    // Simulate unique constraint violation on email
    if (table == 'users' && type == RequestType.insert) {
      throw PostgrestException(
        message: 'duplicate key value violates unique constraint "users_email_key"',
        code: '23505', // Postgres unique violation code
      );
    }
    
    // Simulate permission error for certain operations
    if (table == 'private_data' && type == RequestType.select) {
      throw PostgrestException(
        message: 'permission denied for table private_data',
        code: '42501', // Postgres permission denied code
      );
    }
  },
);

@dshukertjr dshukertjr merged commit 70ec539 into main Feb 12, 2025
1 check passed
@dshukertjr dshukertjr deleted the feat/error branch February 12, 2025 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants