Skip to content

feat: Add support for triggering error for PostgREST methods. #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 12, 2025

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.

1 participant