// Fetches a chapter's raw text for building a study (the free Bible source). The Reader's "Save for // offline" downloads go through the same address, so a saved book builds a study with no connection. // Failures say what's wrong and what to do, instead of a generic error. export async function fetchStudyChapter(translation, bookAbbrev, chapter, { signal } = {}) { const code = translation === 'NET' ? 'eng_net' : (translation || 'BSB'); let res; try { res = await fetch(`https://bible.helloao.org/api/${code}/${bookAbbrev}/${chapter}.json`, { signal }); } catch (err) { if (err?.name === 'AbortError') throw err; const offline = typeof navigator !== 'undefined' && navigator.onLine === false; throw new Error(offline ? "You're offline and this chapter isn't saved on this device. In the Reader, use Save for offline while connected." : 'Could not reach the Bible text. Check your connection and try again.', { cause: err }); } if (res.status === 503) throw new Error("You're offline and this chapter isn't saved on this device. In the Reader, use Save for offline while connected."); if (!res.ok) throw new Error('Unable to load chapter.'); return res.json(); }