Ramda.js R.otherwise() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

R.otherwise(onFailure, promise) is Ramda’s curried .catch: it runs onFailure when a Promise rejects, and returns a new Promise. On success, the original value passes through unchanged.

Stable: R.otherwise has been in Ramda since v0.26.0. It is not deprecated, experimental, or non-standard. Pair with R.andThen for the success path.

Syntax

Call R.otherwise. Start with this line.

Ramda
R.otherwise(onFailure, promise)
CallWhat it does
R.otherwise(onFailure, promise)Primary signature.
R.otherwise(...)Call the function helper.

Prefer import { otherwise } from "ramda" when you want a named import.

Library declarations
Ramda
R.otherwise(onFailure, promise)

Parameters

ParameterDescription
onFailureRequired. Runs on reject; may return a value or Promise
pRequired. A Promise (must have .then)

Return Value

Return ValueDescription
*New Promise from p.then(null, onFailure)

Ramda Examples

Example 1 — Official recoverFromFailure

A fetch that always rejects. Recover with a default member, then pick the name fields.

Ramda
const failedFetch = function (id) {
  return Promise.reject('bad ID');
};
const useDefault = function () {
  return { firstName: 'Bob', lastName: 'Loblaw' };
};

const recoverFromFailure = R.pipe(
  failedFetch,
  R.otherwise(useDefault),
  R.andThen(R.pick(['firstName', 'lastName']))
);

recoverFromFailure(12345).then(console.log);
// → { firstName: 'Bob', lastName: 'Loblaw' }
Try It Yourself

How It Works

  1. Reject. failedFetch always returns Promise.reject('bad ID').
  2. Recover. R.otherwise(useDefault) turns that into Bob Loblaw.
  3. Transform. R.andThen(R.pick(…)) runs on the recovered object.
  4. Order. Recover first, then transform — that is the official recipe.

Example 2 — Success Passes Through; Reject Recovers

The same fallback. A resolved Promise keeps 'ok'. A rejected Promise becomes 'fallback'.

Ramda
const fallback = R.always('fallback');

R.otherwise(fallback, Promise.resolve('ok')).then(console.log);
// → 'ok'

R.otherwise(fallback, Promise.reject('boom')).then(console.log);
// → 'fallback'
Try It Yourself

How It Works

  1. Spare tire. onFailure only runs on reject.
  2. Resolve. 'ok' passes through; fallback is never called.
  3. Reject. R.always('fallback') replaces 'boom'.
  4. Tip. Use a function of err when the reason should appear in the recovery.

Example 3 — Use the Rejection Reason

The official useDefault ignores 'bad ID'. You can read that string instead.

Ramda
const explain = function (err) {
  return 'caught: ' + err;
};

R.otherwise(explain, Promise.reject('bad ID')).then(console.log);
// → 'caught: bad ID'
Try It Yourself

How It Works

  1. Reason. Native .then(null, fn) passes the rejection value as err.
  2. Build a message. explain concatenates 'caught: ' with that reason.
  3. Resolve. Returning a string resolves the new Promise.
  4. Re-reject. Return Promise.reject(…) if the chain should stay failed.

Example 4 — Same Result as Native .catch

Currying is the difference. The settled value is the same 0.

Ramda
Promise.reject('x').catch(R.always(0)).then(console.log);
// → 0

R.otherwise(R.always(0), Promise.reject('x')).then(console.log);
// → 0
Try It Yourself

How It Works

  1. Native. .catch(fn) needs the Promise on the left.
  2. Ramda. R.otherwise(fn) takes the Promise later — pipe-friendly.
  3. Same recovery. Both settle to 0.
  4. Prefer. otherwise in compositions; .catch on a Promise you already hold.

Example 5 — Non-Promise Throws TypeError

Ramda checks for a .then method. A plain 42 is not a Promise.

Ramda
try {
  R.otherwise(R.identity, 42);
} catch (e) {
  console.log(e.message);
}
// → "`otherwise` expected a Promise, received 42"
Try It Yourself

How It Works

  1. Sync check. The throw happens before any .then.
  2. Requirement. The second argument must be thenable.
  3. Pipe tip. Put otherwise only after a step that returns a Promise.
  4. Not async. This is not a rejected Promise — it is a synchronous TypeError.

Browser & Runtime Support

R.otherwise is a Ramda Function helper since v0.26.0. It builds on native Promises (.then). It runs anywhere Ramda 0.26+ and Promises are available.

✓ Stable · Ramda 0.26.0+

R.otherwise()

Needs Ramda 0.26+ and a Promise-capable runtime. Works in evergreen browsers and current Node LTS / Bun / Deno when Ramda is installed.

100% With Ramda 0.26+ & Promises
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.otherwise Ramda 0.26.0+

Bottom line: Safe for production once Ramda 0.26.0+ is loaded in a Promise environment. Use a CDN build such as ramda.min.js in the browser, or npm install ramda for Node. Very old browsers without Promises need a Promise polyfill.

Frequently Asked Questions

R.otherwise(onFailure, promise) returns promise.then(null, onFailure). It runs onFailure when the Promise rejects, and returns a new Promise. If the original Promise resolves, onFailure is skipped and the success value passes through. Added in v0.26.0. See also R.andThen.
failedFetch always rejects with 'bad ID'. useDefault returns { firstName: 'Bob', lastName: 'Loblaw' }. recoverFromFailure = R.pipe(failedFetch, R.otherwise(useDefault), R.andThen(R.pick(['firstName', 'lastName']))). recoverFromFailure(12345) resolves to { firstName: 'Bob', lastName: 'Loblaw' }.
andThen is the success path: promise.then(onSuccess). otherwise is the failure path: promise.then(null, onFailure). Put otherwise before andThen in a pipe when you want to recover, then transform the recovered value.
No. A resolved Promise skips onFailure. R.otherwise(R.always('fallback'), Promise.resolve('ok')) still resolves to 'ok'.
Ramda throws a TypeError: `otherwise` expected a Promise, received … The second argument must have a .then method.
No. R.otherwise is a stable Ramda Function helper from v0.26.0. It is not deprecated, experimental, or non-standard.

About the author

Next: R.partial()

Pre-fill some arguments of a function and get a new function for the rest.

R.partial() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful