runAction method

  1. @override
Future<ActionResult> runAction(
  1. String resourceKey,
  2. Object id,
  3. String action
)
override

POST /{resource}/{id}/actions/{action} — runs one of the record's own RecordActions. Never throws on a 4xx or 5xx; see ActionResult.

The caller re-fetches the record on success only: the action may have changed fields, permissions or the action list itself, and this method carries none of that back — only whether it ran. A failure leaves the record untouched, so there is nothing to re-fetch.

Implementation

@override
Future<ActionResult> runAction(
  String resourceKey,
  Object id,
  String action,
) async {
  try {
    final response = await _transport.post(
      '$prefix/$resourceKey/$id/actions/$action',
      const {},
    );

    final message = response.body['message'];

    // 2xx is the only success. Every other status — 403, 404, 422, 500 —
    // is a refusal or a fault, and either leaves the record untouched
    // from the client's point of view: only a success triggers the
    // caller's re-fetch.
    return response.statusCode >= 200 && response.statusCode < 300
        ? ActionSuccess(message is String ? message : null)
        : ActionFailed(message is String ? message : null);
  } catch (e) {
    // Same contract as create/update/destroy: the transport throws on
    // socket/DNS/timeout, and a tapped button with no network must come
    // back as a failed action, never an unhandled async error.
    return ActionFailed(messageOf(e));
  }
}