function::user_int64_error - Linux
Overview
function::user_int64_error is a command used to handle user-defined errors within Google Cloud Functions executed in a Node.js runtime. It’s primarily useful for creating custom error responses, such as returning specific HTTP status codes or error messages.
Syntax
function::user_int64_error(message: string, httpCode: int, metadata: object)
Options/Flags
- message: The error message to be included in the error response.
- httpCode: The HTTP status code to be returned in the error response. Defaults to 500 (Internal Server Error).
- metadata: An optional object containing additional metadata to be included in the error response.
Examples
Simple Usage:
const {user_int64_error} = require('firebase-functions/v1');
exports.helloWorld = async (request, response) => {
const error = user_int64_error('Error occurred', 404);
response.status(error.status).send(error.message);
};
Custom Metadata:
const error = user_int64_error('Invalid request', 400, {
errorType: 'validation_error',
userId: 'user123'
});
Common Issues
- Incorrect HTTP Code: Using an invalid or unsupported HTTP status code may result in unexpected behavior or errors.
- Missing Error Message: Failing to provide an error message will result in a default error message being returned.
Integration
Combining with Other Commands:
- Use function::logger to log error details for debugging.
- Use function::http to set custom HTTP response headers.
Related Commands
- function::logger: Logs messages to the Cloud Functions logs.
- function::http: Handles HTTP requests and responses.