---
name: "up.Request.prototype.then"
area: "API"
kind: "Instance method"
parent: "up.Request class"
url: "https://unpoly.com/api/up.Request.prototype.then"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.Request class](https://unpoly.com/api/up.Request.md)</nav>

# up.Request.prototype.then(onFulfilled, onRejected)

An [`up.Request`](https://unpoly.com/api/up.Request.md) is also a promise for the server response.

A request is _fulfilled_ with an [`up.Response`](https://unpoly.com/api/up.Response.md) when the server sends a response with a status code of 2xx or [304](https://unpoly.com/learn/conditional-requests.md#rendering-nothing).

The promise will reject for responses with an [HTTP error status](https://unpoly.com/learn/error-responses.md), when the request is [aborted](https://unpoly.com/learn/aborting-requests.md) or when there is a [network issue](https://unpoly.com/learn/network-issues.md).

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

```js
try {
  let response = await up.request('foo')
  console.log('Successful response:', response.text)
} catch (error) {
  if (error instanceof up.Response) {
    console.log('Response with error code:', error.text)
  } else {
    console.log("Other error during request:", error)
  }
}
```

---

## Parameters {#parameters}

### onFulfilled {#onFulfilled}

(required)

Type: Function([up.Response](https://unpoly.com/api/up.Response.md))

### onRejected {#onRejected}

(required)

Type: Function([up.Response](https://unpoly.com/api/up.Response.md)|[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error))

---

## Return value {#return-value}

A promise that fulfills when the server response was fully loaded.

Type: [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)<[up.Response](https://unpoly.com/api/up.Response.md)>

