Skip to content

Validation and errors ​

Fetch throws a Victorycodedev\NativephpFetch\Exceptions\FetchException when a request is configured incorrectly or the native bridge rejects the work. These exceptions are thrown synchronously, before any network activity begins, so you can catch them at the call site.

Configuration validation ​

ConditionMessage
timeout() less than 1 secondFetch timeout must be at least 1 second.
retry() with negative timesFetch retry times cannot be negative.
retry() with negative delayFetch retry delay cannot be negative.
retry() with multiplier below 1.0Fetch retry multiplier must be at least 1.0.
retry() with maxDelay below delayFetch retry maxDelay must be greater than or equal to delay.
retry() with a non-integer or out-of-range statusFetch retry statuses must contain valid integer HTTP status codes.
Empty baseUrl()Fetch base URL cannot be empty.
Empty withBody() content typeFetch raw body content type cannot be empty.

Body and attachment rules ​

ConditionMessage
asJson(), asForm(), or withBody() with existing attachmentsFetch attachments cannot be combined with {JSON, form, raw body} bodies.
raw body combined with method dataFetch raw bodies cannot be combined with method data.
get() with a body or attachmentsFetch request bodies cannot be sent with a GET request. / Fetch attachments cannot be sent with a GET request.
Empty attachment field name or pathFetch attachment field name cannot be empty. / Fetch attachment path cannot be empty.
Attachment without a determinable filenameFetch could not determine an attachment filename.
Malformed attachMany() entriesFetch attachment at index {n} ...

Runtime errors ​

php
try {
    Fetch::post($url, $data);
} catch (Victorycodedev\NativephpFetch\Exceptions\FetchException $e) {
    $this->error = $e->getMessage();
}

When the NativePHP mobile bridge is unavailable — for example in a queued job, scheduled task, or CLI command — starting work throws Fetch requires the NativePHP Mobile runtime.

A transport problem after the request is accepted does not throw. It is delivered asynchronously through FetchRequestFailed with a code and message instead. See Events and responses.

Released under the MIT License.