Skip to main content

Capture Errors

Send errors to Reflex via the API.

Capture Exception

POST /api/v1/errors

Request

curl https://reflex.brainzlab.ai/api/v1/errors \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "exception": {
      "type": "PaymentError",
      "message": "Card declined",
      "backtrace": [
        "app/services/payment.rb:45:in `charge`",
        "app/controllers/orders_controller.rb:23:in `create`"
      ]
    },
    "level": "error",
    "user": {
      "id": "123",
      "email": "[email protected]"
    },
    "tags": {
      "feature": "checkout"
    },
    "extra": {
      "order_id": 456,
      "amount": 99.99
    }
  }'

Parameters

FieldTypeRequiredDescription
exception.typestringYesException class name
exception.messagestringYesError message
exception.backtracearrayNoStack trace lines
levelstringNoSeverity: warning, error, fatal
userobjectNoUser context
tagsobjectNoIndexed tags
extraobjectNoAdditional data
breadcrumbsarrayNoEvents before error
contextobjectNoRequest/environment context

Response

{
  "data": {
    "id": "evt_abc123",
    "error_id": "err_xyz789",
    "status": "captured"
  }
}

Capture Message

For error-like events without an exception:
POST /api/v1/messages

Request

curl https://reflex.brainzlab.ai/api/v1/messages \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Unexpected state encountered",
    "level": "warning",
    "extra": {
      "state": "invalid",
      "expected": "active"
    }
  }'

With Breadcrumbs

Include events leading up to the error:
{
  "exception": { ... },
  "breadcrumbs": [
    {
      "timestamp": "2024-01-15T10:00:00Z",
      "category": "http",
      "message": "GET /api/user",
      "level": "info"
    },
    {
      "timestamp": "2024-01-15T10:00:01Z",
      "category": "ui",
      "message": "User clicked checkout",
      "level": "info"
    }
  ]
}

With Context

Include request and environment context:
{
  "exception": { ... },
  "context": {
    "request": {
      "url": "https://app.example.com/checkout",
      "method": "POST",
      "headers": { "User-Agent": "..." }
    },
    "environment": {
      "ruby_version": "3.2.0",
      "rails_version": "7.1.0"
    },
    "git": {
      "commit": "abc123",
      "branch": "main"
    }
  }
}

Bulk Capture

Send multiple errors:
POST /api/v1/errors/bulk
Limited to 100 errors per request.