Skip to content

Commit d1d9b01

Browse files
committed
Make FunctionsError class public
1 parent f3402b9 commit d1d9b01

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

common/api-review/functions.api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
```ts
66

77
import { FirebaseApp } from '@firebase/app';
8+
import { FirebaseError } from '@firebase/util';
89

910
// @public
1011
export function connectFunctionsEmulator(functionsInstance: Functions, host: string, port: number): void;
@@ -16,6 +17,14 @@ export interface Functions {
1617
region: string;
1718
}
1819

20+
// @public
21+
export class FunctionsError extends FirebaseError {
22+
constructor(
23+
code: FunctionsErrorCodeCore, message?: string,
24+
details?: unknown);
25+
readonly details?: unknown;
26+
}
27+
1928
// @public
2029
export type FunctionsErrorCode = `functions/${FunctionsErrorCodeCore}`;
2130

docs-devsite/functions.functionserror.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,50 @@ overwritten. Changes should be made in the source code at
99
https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

12-
# FunctionsError interface
13-
An error returned by the Firebase Functions client SDK.
12+
# FunctionsError class
13+
An explicit error that can be thrown from a handler to send an error to the client that called the function.
14+
15+
See [FunctionsErrorCode](./functions.md#functionserrorcode) for full documentation of codes.
1416

1517
<b>Signature:</b>
1618

1719
```typescript
18-
export interface FunctionsError extends FirebaseError
20+
export declare class FunctionsError extends FirebaseError
1921
```
2022
<b>Extends:</b> [FirebaseError](./util.firebaseerror.md#firebaseerror_class)
2123
22-
## Properties
24+
## Constructors
2325
24-
| Property | Type | Description |
26+
| Constructor | Modifiers | Description |
2527
| --- | --- | --- |
26-
| [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. |
27-
| [details](./functions.functionserror.md#functionserrordetails) | unknown | Extra data to be converted to JSON and included in the error response. |
28+
| [(constructor)(code, message, details)](./functions.functionserror.md#functionserrorconstructor) | | Constructs a new instance of the <code>FunctionsError</code> class |
29+
30+
## Properties
2831
29-
## FunctionsError.code
32+
| Property | Modifiers | Type | Description |
33+
| --- | --- | --- | --- |
34+
| [details](./functions.functionserror.md#functionserrordetails) | | unknown | Extra data to be converted to JSON and included in the error response. |
3035
31-
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.
36+
## FunctionsError.(constructor)
37+
38+
Constructs a new instance of the `FunctionsError` class
3239
3340
<b>Signature:</b>
3441
3542
```typescript
36-
readonly code: FunctionsErrorCode;
43+
constructor(
44+
code: FunctionsErrorCode, message?: string,
45+
details?: unknown);
3746
```
3847
48+
#### Parameters
49+
50+
| Parameter | Type | Description |
51+
| --- | --- | --- |
52+
| code | [FunctionsErrorCode](./functions.md#functionserrorcodecore) | |
53+
| message | string | |
54+
| details | unknown | |
55+
3956
## FunctionsError.details
4057
4158
Extra data to be converted to JSON and included in the error response.

docs-devsite/functions.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ Cloud Functions for Firebase
2323
| [httpsCallable(functionsInstance, name, options)](./functions.md#httpscallable_1dd297c) | Returns a reference to the callable HTTPS trigger with the given name. |
2424
| [httpsCallableFromURL(functionsInstance, url, options)](./functions.md#httpscallablefromurl_7af6987) | Returns a reference to the callable HTTPS trigger with the specified url. |
2525

26+
## Classes
27+
28+
| Class | Description |
29+
| --- | --- |
30+
| [FunctionsError](./functions.functionserror.md#functionserror_class) | An explicit error that can be thrown from a handler to send an error to the client that called the function.<!-- -->See [FunctionsErrorCode](./functions.md#functionserrorcode) for full documentation of codes. |
31+
2632
## Interfaces
2733

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

packages/functions/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
getDefaultEmulatorHostnameAndPort
3333
} from '@firebase/util';
3434

35+
export { FunctionsError } from './error';
3536
export * from './public-types';
3637

3738
/**

packages/functions/src/error.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ const errorCodeMap: { [name: string]: FunctionsErrorCode } = {
5151
/**
5252
* An explicit error that can be thrown from a handler to send an error to the
5353
* client that called the function.
54+
*
55+
* See {@link FunctionsErrorCode} for full documentation of codes.
56+
*
57+
* @public
5458
*/
5559
export class FunctionsError extends FirebaseError {
5660
constructor(
@@ -66,7 +70,10 @@ export class FunctionsError extends FirebaseError {
6670
readonly details?: unknown
6771
) {
6872
super(`${FUNCTIONS_TYPE}/${code}`, message || '');
69-
// TODO (dlarocque): Set this to be the root of the stack trace.
73+
74+
// Since the FirebaseError constructor sets the prototype of `this` to FirebaseError.prototype,
75+
// we also have to do it in all subclasses to allow for correct `instanceof` checks.
76+
Object.setPrototypeOf(this, FunctionsError.prototype);
7077
}
7178
}
7279

0 commit comments

Comments
 (0)