Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tender-tips-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/functions': patch
---

Make the `FunctionsError` class publicly exported.
6 changes: 4 additions & 2 deletions common/api-review/functions.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export interface Functions {
}

// @public
export interface FunctionsError extends FirebaseError {
readonly code: FunctionsErrorCode;
export class FunctionsError extends FirebaseError {
constructor(
code: FunctionsErrorCodeCore, message?: string,
details?: unknown);
readonly details?: unknown;
}

Expand Down
35 changes: 26 additions & 9 deletions docs-devsite/functions.functionserror.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,50 @@ overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# FunctionsError interface
# FunctionsError class
An error returned by the Firebase Functions client SDK.

See [FunctionsErrorCode](./functions.md#functionserrorcode) for full documentation of codes.

<b>Signature:</b>

```typescript
export interface FunctionsError extends FirebaseError
export declare class FunctionsError extends FirebaseError
```
<b>Extends:</b> [FirebaseError](./util.firebaseerror.md#firebaseerror_class)

## Properties
## Constructors

| Property | Type | Description |
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [code](./functions.functionserror.md#functionserrorcode) | [FunctionsErrorCode](./functions.md#functionserrorcode) | A standard error code that will be returned to the client. This also determines the HTTP status code of the response, as defined in code.proto. |
| [details](./functions.functionserror.md#functionserrordetails) | unknown | Extra data to be converted to JSON and included in the error response. |
| [(constructor)(code, message, details)](./functions.functionserror.md#functionserrorconstructor) | | Constructs a new instance of the <code>FunctionsError</code> class |

## Properties

## FunctionsError.code
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [details](./functions.functionserror.md#functionserrordetails) | | unknown | Extra data to be converted to JSON and included in the error response. |

A standard error code that will be returned to the client. This also determines the HTTP status code of the response, as defined in code.proto.
## FunctionsError.(constructor)

Constructs a new instance of the `FunctionsError` class

<b>Signature:</b>

```typescript
readonly code: FunctionsErrorCode;
constructor(
code: FunctionsErrorCode, message?: string,
details?: unknown);
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| code | [FunctionsErrorCode](./functions.md#functionserrorcodecore) | |
| message | string | |
| details | unknown | |

## FunctionsError.details

Extra data to be converted to JSON and included in the error response.
Expand Down
7 changes: 6 additions & 1 deletion docs-devsite/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ Cloud Functions for Firebase
| [httpsCallable(functionsInstance, name, options)](./functions.md#httpscallable_1dd297c) | Returns a reference to the callable HTTPS trigger with the given name. |
| [httpsCallableFromURL(functionsInstance, url, options)](./functions.md#httpscallablefromurl_7af6987) | Returns a reference to the callable HTTPS trigger with the specified url. |

## Classes

| Class | Description |
| --- | --- |
| [FunctionsError](./functions.functionserror.md#functionserror_class) | An error returned by the Firebase Functions client SDK.<!-- -->See [FunctionsErrorCode](./functions.md#functionserrorcode) for full documentation of codes. |

## Interfaces

| Interface | Description |
| --- | --- |
| [Functions](./functions.functions.md#functions_interface) | A <code>Functions</code> instance. |
| [FunctionsError](./functions.functionserror.md#functionserror_interface) | An error returned by the Firebase Functions client SDK. |
| [HttpsCallableOptions](./functions.httpscallableoptions.md#httpscallableoptions_interface) | An interface for metadata about how calls should be executed. |
| [HttpsCallableResult](./functions.httpscallableresult.md#httpscallableresult_interface) | An <code>HttpsCallableResult</code> wraps a single result from a function call. |

Expand Down
1 change: 1 addition & 0 deletions packages/functions/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getDefaultEmulatorHostnameAndPort
} from '@firebase/util';

export { FunctionsError } from './error';
export * from './public-types';

/**
Expand Down
1 change: 1 addition & 0 deletions packages/functions/src/callable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async function expectError(
await promise;
} catch (e) {
failed = true;
expect(e).to.be.instanceOf(FunctionsError);
const error = e as FunctionsError;
expect(error.code).to.equal(`${FUNCTIONS_TYPE}/${code}`);
expect(error.message).to.equal(message);
Expand Down
11 changes: 9 additions & 2 deletions packages/functions/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ const errorCodeMap: { [name: string]: FunctionsErrorCode } = {
};

/**
* An explicit error that can be thrown from a handler to send an error to the
* client that called the function.
* An error returned by the Firebase Functions client SDK.
*
* See {@link FunctionsErrorCode} for full documentation of codes.
*
* @public
*/
export class FunctionsError extends FirebaseError {
constructor(
Expand All @@ -66,6 +69,10 @@ export class FunctionsError extends FirebaseError {
readonly details?: unknown
) {
super(`${FUNCTIONS_TYPE}/${code}`, message || '');

// Since the FirebaseError constructor sets the prototype of `this` to FirebaseError.prototype,
// we also have to do it in all subclasses to allow for correct `instanceof` checks.
Object.setPrototypeOf(this, FunctionsError.prototype);
}
}

Expand Down
18 changes: 0 additions & 18 deletions packages/functions/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/
import { FirebaseApp } from '@firebase/app';
import { FirebaseError } from '@firebase/util';

/**
* An `HttpsCallableResult` wraps a single result from a function call.
Expand Down Expand Up @@ -144,23 +143,6 @@ export type FunctionsErrorCodeCore =
*/
export type FunctionsErrorCode = `functions/${FunctionsErrorCodeCore}`;

/**
* An error returned by the Firebase Functions client SDK.
* @public
*/
export interface FunctionsError extends FirebaseError {
/**
* A standard error code that will be returned to the client. This also
* determines the HTTP status code of the response, as defined in code.proto.
*/
readonly code: FunctionsErrorCode;

/**
* Extra data to be converted to JSON and included in the error response.
*/
readonly details?: unknown;
}

declare module '@firebase/component' {
interface NameServiceMapping {
'functions': Functions;
Expand Down
Loading