KSvend Claude Happy commited on
Commit
73c5feb
·
1 Parent(s): e8c214d

fix: Content-Type header dropped when authenticated, causing 422 on job submit

Browse files

The spread { ...defaults, ...opts } overwrote the merged headers with
opts.headers (which only had Authorization). Now headers are built once
and passed as the final value.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>

Files changed (1) hide show
  1. frontend/js/api.js +3 -8
frontend/js/api.js CHANGED
@@ -12,17 +12,12 @@ const BASE = ''; // same-origin; empty string = relative to current host
12
  * @returns {Promise<any>}
13
  */
14
  async function apiFetch(path, opts = {}) {
 
15
  const session = JSON.parse(sessionStorage.getItem('aperture_session') || 'null');
16
  if (session) {
17
- opts.headers = {
18
- ...opts.headers,
19
- 'Authorization': `Bearer ${session.email}:${session.token}`,
20
- };
21
  }
22
- const defaults = {
23
- headers: { 'Content-Type': 'application/json', ...(opts.headers || {}) },
24
- };
25
- const res = await fetch(BASE + path, { ...defaults, ...opts });
26
  if (!res.ok) {
27
  let detail = res.statusText;
28
  try {
 
12
  * @returns {Promise<any>}
13
  */
14
  async function apiFetch(path, opts = {}) {
15
+ const headers = { 'Content-Type': 'application/json', ...(opts.headers || {}) };
16
  const session = JSON.parse(sessionStorage.getItem('aperture_session') || 'null');
17
  if (session) {
18
+ headers['Authorization'] = `Bearer ${session.email}:${session.token}`;
 
 
 
19
  }
20
+ const res = await fetch(BASE + path, { ...opts, headers });
 
 
 
21
  if (!res.ok) {
22
  let detail = res.statusText;
23
  try {