summaryrefslogtreecommitdiff
path: root/src/lib/safe-action.ts
blob: 846f2ef4275f7f7bed7b78b9aeeb78d5b099a99b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import {
  DEFAULT_SERVER_ERROR_MESSAGE,
  createSafeActionClient,
} from 'next-safe-action';

export class ActionError extends Error {}

export const actionClient = createSafeActionClient({
  handleServerError(e) {
    console.error('Failed to execute action:', e.message);

    if (e instanceof ActionError) {
      return e.message;
    }

    return DEFAULT_SERVER_ERROR_MESSAGE;
  },
});