Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 1, 2025

Problem

Users were encountering a 500 Internal Server Error when accessing the /api/seats endpoint:

500 Internal Server Error – most likely a bug in the app.  
Error: [GET] "/api/seats": 500 Server Error

This occurred when the GitHub Copilot billing seats API returned entries where the assignee field is null. This happens when a user has been removed from the organization but their seat assignment still exists in the system as a deprecated entry.

Root Cause

The Seat model constructor was attempting to access data.assignee.login and data.assignee.id without null checks:

// Before (causing the error)
constructor(data: any) {
    this.login = data.assignee.login;      // ❌ Throws if assignee is null
    this.id = data.assignee.id;            // ❌ Throws if assignee is null
    this.team = data.assigning_team ? data.assigning_team.name : '';
    // ...
}

When data.assignee was null, this resulted in TypeError: Cannot read properties of null (reading 'login'), causing the 500 server error.

Solution

Added null safety checks with appropriate fallback values:

// After (handles null assignee gracefully)
constructor(data: any) {
    this.login = data.assignee ? data.assignee.login : 'deprecated';  // ✅ Safe fallback
    this.id = data.assignee ? data.assignee.id : 0;                   // ✅ Safe fallback
    this.team = data.assigning_team ? data.assigning_team.name : '';
    // ...
}

Changes Made

  1. Fixed Seat.ts constructor: Added null checks for data.assignee with sensible fallback values
  2. Added comprehensive tests: Created 5 test cases covering various null scenarios
  3. Updated mock data: Enhanced sample JSON files to include deprecated seats for better testing

Testing

  • ✅ All existing tests continue to pass
  • ✅ New tests specifically validate the null assignee scenario
  • ✅ Build process completes successfully
  • ✅ Mock data includes realistic deprecated seat examples

The fix ensures that deprecated seats (with null assignees) are displayed with login: 'deprecated' and id: 0 instead of causing server crashes.

Fixes #209.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.fontshare.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • api.fontsource.org
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.bunny.net
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.google.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.googleapis.com
    • Triggering command: node (vitest 1) (dns block)
    • Triggering command: node (vitest 2) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Encountering a 500 Internal Server Error. Fix null assignee handling in Seat model to prevent 500 Internal Server Error Jul 1, 2025
@Copilot Copilot AI requested a review from karpikpl July 1, 2025 22:22
Copilot finished work on behalf of karpikpl July 1, 2025 22:22
@karpikpl karpikpl marked this pull request as ready for review July 2, 2025 02:19
@karpikpl karpikpl merged commit 0a85900 into main Jul 7, 2025
6 checks passed
@karpikpl karpikpl deleted the copilot/fix-209 branch July 7, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encountering a 500 Internal Server Error.
2 participants