octokit request error - JSON web token could not be decoded
Author: jardonCreated Oct 21, 2025Updated Oct 31, 2025
Bug Report
starting with probot v13.0.0, the below test fails as the nock requests stay in a pending state and fail the expect.
import nock from "nock";
import { myProbotApp } from "../app.js";
import { Probot, ProbotOctokit } from "probot";
import { jest } from '@jest/globals';
import fs from "fs";
import path from "path";
import { fileURLToPath } from 'url';
import pino from 'pino';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const repoCreatedPayload = JSON.parse(fs.readFileSync(path.join(__dirname, "fixtures/repository.created.json"), 'utf8'));
const collaboratorRemovedBody = {"permission": "pull"};
const logger = pino();
const privateKey = fs.readFileSync(
path.join(__dirname, "fixtures/mock-cert.pem"),
"utf-8"
);
describe("My Probot app", () => {
let probot;
beforeEach(() => {
nock.disableNetConnect();
probot = new Probot({
appId: 123,
privateKey,
Octokit: ProbotOctokit.defaults({
retry: { enabled: false },
throttle: { enabled: false },
}),
log: logger,
});
myProbotApp(probot);
});
test("non-forked repo is created, events happen as expected", async () => {
process.env.SA_WHITELIST = "svc_account";
process.env.PAVED_PATH_TEMPLATES = "test-template"
process.env.PAVED_PATH_TEAM = "test-team"
process.env.ORG = "SAMPLE-ORG";
nock("https://api.github.com")
.post("/app/installations/123/access_tokens")
.reply(200, {
token: "test",
permissions: {
issues: "write",
},
})
nock("https://api.github.com")
.post("/repos/SAMPLE-ORG/tester-fork/issues")
.reply(200);
nock("https://api.github.com")
.get("/repos/SAMPLE-ORG/tester-fork")
.reply(200, { default_branch: "main", owner: { login : "svc_account" } });
nock("https://api.github.com")
.put("/repos/SAMPLE-ORG/tester-fork/collaborators/homer_thdgit", (body) => {
expect(body).toMatchObject(collaboratorRemovedBody);
return true;
})
.reply(200);
nock("https://api.github.com")
.put("/repos/SAMPLE-ORG/tester-fork/branches/main/protection")
.reply(200);
// Receive a webhook event
await probot.receive({ name: "repository.created", payload: repoCreatedPayload });
// validate all mocks were called
expect(nock.pendingMocks()).toStrictEqual([]);
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
jest.clearAllMocks();
});
});RequestError [HttpError]: A JSON web token could not be decoded - https://docs.github.com/rest
at /Users/JMD8SAG/Projects/protectolator/node_modules/[@octokit/request/dist-node/index.js:125:21](https://matrix.to/#/@octokit/request/dist-node/index.js:125:21)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at hook (/Users/username/Projects/project1/node_modules/[@octokit/auth-app/dist-node/index.js:365:18](https://matrix.to/#/@octokit/auth-app/dist-node/index.js:365:18))
at Job.doExecute (/Users/username/Projects/project1/node_modules/bottleneck/light.js:405:18) {
status: 401,
response: {
url: 'https://api.github.com/app/installations/123/access_tokens',
status: 401,
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
'content-length': '117',
'content-security-policy': "default-src 'none'",
'content-type': 'application/json; charset=utf-8',
date: 'Tue, 21 Oct 2025 00:32:07 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: '[github.com](http://github.com/)',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-media-type': 'github.v3; format=json',
'x-github-request-id': '2712:386DA2:2A3D62C:B34F859:68F6D487',
'x-xss-protection': '0'
},
data: {
message: 'A JSON web token could not be decoded',
documentation_url: 'https://docs.github.com/rest',
status: '401'
}
},
request: {
method: 'POST',
url: 'https://api.github.com/app/installations/123/access_tokens',
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'probot/13.0.0 octokit-core.js/5.2.2 Node.js/18.20.5 (darwin; arm64)',
authorization: 'bearer [REDACTED]'
},
request: { hook: [Function: bound bound register] }
}
}Expected behavior/code the nocks should process correctly and no longer be pending allowing the tests to pass.
Environment
- Probot version(s):
^13.0.0 - Node/npm version: 24.x
- OS: macOS
Source: probot/probot