Skip to content

[fix] Supertest - GCP Error - 2 UNKNOWN: Getting metadata from plugin failed with error: Unexpected Gaxios Error #871

@bhala-ki

Description

@bhala-ki

Describe the bug

Node.js version: v25.1.0

OS version: macOS Tahoe 26.1

Description: Getting an error "2 UNKNOWN: Getting metadata from plugin failed with error: Unexpected Gaxios Error" while trying to retrieve the GCP secret.

Actual behavior

Getting an error "2 UNKNOWN: Getting metadata from plugin failed with error: Unexpected Gaxios Error" while trying to retrieve the GCP secret.

Expected behavior

Should be able to retrieve the GCP secrets successfully without any errors.

Code to reproduce

import request, { Response } from "supertest";

describe("Endpoints", () => {
let authToken: string;
beforeAll(async () => {
authToken = await getAccessToken(BASE_URL);
});

export async function getAccessToken(baseUrl: string): Promise {
const username = await getSecretValue("<secret_name>");
const reqBody = "<request_body>";

request(baseUrl)
.post("/auth/token")
.auth(username)
.set("Content-Type", "application/x-www-form-urlencoded")
.send(reqBody);
}

import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
import { gcp_secret_project_name } from '../../config';

const client = new SecretManagerServiceClient();

export async function getSecretValue(secretId: string): Promise {
const [version] = await client.accessSecretVersion({
name: projects/${gcp_secret_project_name}/secrets/${secretId}/versions/latest,
});

return version.payload?.data?.toString() || '';
}

Failing in this line of code: await client.accessSecretVersion({
name: projects/${gcp_secret_project_name}/secrets/${secretId}/versions/latest,
});
with:
2 UNKNOWN: Getting metadata from plugin failed with error: Unexpected Gaxios Error

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions