-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jh/read-me-follow-ons
- Loading branch information
Showing
121 changed files
with
2,877 additions
and
391 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { ErrorRequestHandler } from "express"; | ||
import { ServerError } from "./serverError.js"; | ||
import airbrake from "../airbrake.js"; | ||
|
||
/** | ||
* Check for expired JWTs, redirect to /logout if found | ||
*/ | ||
export const expiredJWTHandler: ErrorRequestHandler = ( | ||
errorObject, | ||
_res, | ||
res, | ||
next, | ||
) => { | ||
const isJWTExpiryError = | ||
errorObject?.name === "UnauthorizedError" && | ||
errorObject?.message === "jwt expired"; | ||
|
||
if (!isJWTExpiryError) return next(errorObject); | ||
|
||
const logoutPage = new URL("/logout", process.env.EDITOR_URL_EXT!).toString(); | ||
return res.redirect(logoutPage); | ||
}; | ||
|
||
/** | ||
* Fallback error handler | ||
* Must be final Express middleware | ||
*/ | ||
export const errorHandler: ErrorRequestHandler = ( | ||
errorObject, | ||
_req, | ||
res, | ||
_next, | ||
) => { | ||
const { status = 500, message = "Something went wrong" } = (() => { | ||
if ( | ||
airbrake && | ||
(errorObject instanceof Error || errorObject instanceof ServerError) | ||
) { | ||
airbrake.notify(errorObject); | ||
return { | ||
...errorObject, | ||
message: errorObject.message.concat(", this error has been logged"), | ||
}; | ||
} else { | ||
console.log(errorObject); | ||
return errorObject; | ||
} | ||
})(); | ||
|
||
res.status(status).send({ | ||
error: message, | ||
}); | ||
}; |
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
Oops, something went wrong.