mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 22:01:50 +00:00
Handle OAuth2 token errors separately from regular server errors
This commit is contained in:
parent
828385d0eb
commit
6f75185e74
1 changed files with 8 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
import { error, notFound } from "./responses";
|
||||
import { clientError, error, notFound } from "./responses";
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import { initAuth } from "./auth";
|
||||
|
@ -6,6 +6,7 @@ import { initGuildsAPI } from "./guilds";
|
|||
import { initArchives } from "./archives";
|
||||
import { connect } from "../data/db";
|
||||
import path from "path";
|
||||
import { TokenError } from "passport-oauth2";
|
||||
|
||||
require("dotenv").config({ path: path.resolve(__dirname, "..", "..", "api.env") });
|
||||
|
||||
|
@ -31,8 +32,12 @@ connect().then(() => {
|
|||
|
||||
// Error response
|
||||
app.use((err, req, res, next) => {
|
||||
console.error(err);
|
||||
error(res, "Server error", err.status || 500);
|
||||
if (err instanceof TokenError) {
|
||||
clientError(res, "Invalid code");
|
||||
} else {
|
||||
console.error(err);
|
||||
error(res, "Server error", err.status || 500);
|
||||
}
|
||||
});
|
||||
|
||||
// 404 response
|
||||
|
|
Loading…
Add table
Reference in a new issue