Skip to content

Make the FunctionsError class publicly exported #8546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 27 additions & 10 deletions docs-devsite/functions.functionserror.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,53 @@ 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 | Additional details 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.
Additional details to be converted to JSON and included in the error response.

<b>Signature:</b>

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
16 changes: 13 additions & 3 deletions packages/functions/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ 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 {
/**
* Constructs a new instance of the `FunctionsError` class.
*/
constructor(
/**
* A standard error code that will be returned to the client. This also
Expand All @@ -61,11 +67,15 @@ export class FunctionsError extends FirebaseError {
code: FunctionsErrorCode,
message?: string,
/**
* Extra data to be converted to JSON and included in the error response.
* Additional details to be converted to JSON and included in the error response.
*/
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