-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved error handling #178
Open
afischer
wants to merge
5
commits into
main
Choose a base branch
from
error-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
613ae36
initial pass at some preemptive error checks
afischer c08460a
Less noise in logs, pass error to 500 page
afischer aa46eba
Error for empty tree
afischer 7825c2f
pull email from auth client for error message
afischer f48a45c
Resolve conflicts
afischer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const messages = require('./messages') | ||
|
||
// For now, this should just throw for things that would stop the app from booting. | ||
|
||
module.exports = () => { | ||
const { errorMessages } = messages | ||
const { APPROVED_DOMAINS, DRIVE_TYPE, DRIVE_ID } = process.env | ||
const errors = [] | ||
|
||
if (!APPROVED_DOMAINS) errors.push(errorMessages.noApprovedDomains) | ||
if (!DRIVE_TYPE) errors.push(errorMessages.noDriveType) | ||
if (!DRIVE_ID) errors.push(errorMessages.noDriveID) | ||
|
||
if (errors.length) { | ||
console.log('***********************************************') | ||
console.log('Your library instance has configuration issues:') | ||
errors.forEach((message) => console.error(` > ${message}`)) | ||
console.log('Address these issues and restart the app.') | ||
console.log('***********************************************') | ||
process.exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"errorMessages": { | ||
"noApprovedDomains": "You must set the APPROVED_DOMAINS environment variable to a list of domains or a regular expression.", | ||
"noDriveType": "No DRIVE_TYPE env variable set. Please set it to 'team' or 'folder.'", | ||
"noDriveID": "No DRIVE_ID env variable set. Set this environment variable to the ID of your drive or folder and restart the app.", | ||
"noFilesFound": "No files found. Ensure your DRIVE_ID and DRIVE_TYPE environment variables are set correctly and that your service account's email is shared with your drive or folder.\n\nIf you just added the account, wait a minute and try again." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
const search = require('../search') | ||
|
||
const {getAuth} = require('../auth') | ||
const {errorMessages} = require('../errors/messages.json') | ||
|
||
const router = require('express-promise-router')() | ||
|
||
const {getTree, getFilenames, getMeta, getTagged} = require('../list') | ||
|
@@ -62,6 +65,12 @@ async function handlePage(req, res) { | |
|
||
if (page === 'categories' || page === 'index') { | ||
const tree = await getTree() | ||
if (!tree.children) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 This signal is great. It also seems like we could easily make this nonfatal (log, but have the library site be empty) if we wanted. |
||
// pull the auth client email to make debugging easier: | ||
const authClient = await getAuth() | ||
const errMsg = errorMessages.noFilesFound.replace('email', `email (<code>${authClient.email}</code>)`) | ||
throw new Error(errMsg) | ||
} | ||
const categories = buildDisplayCategories(tree) | ||
res.format({ | ||
html: () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Should we include the full trace here, too?