mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +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 express from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import { initAuth } from "./auth";
|
import { initAuth } from "./auth";
|
||||||
|
@ -6,6 +6,7 @@ import { initGuildsAPI } from "./guilds";
|
||||||
import { initArchives } from "./archives";
|
import { initArchives } from "./archives";
|
||||||
import { connect } from "../data/db";
|
import { connect } from "../data/db";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { TokenError } from "passport-oauth2";
|
||||||
|
|
||||||
require("dotenv").config({ path: path.resolve(__dirname, "..", "..", "api.env") });
|
require("dotenv").config({ path: path.resolve(__dirname, "..", "..", "api.env") });
|
||||||
|
|
||||||
|
@ -31,8 +32,12 @@ connect().then(() => {
|
||||||
|
|
||||||
// Error response
|
// Error response
|
||||||
app.use((err, req, res, next) => {
|
app.use((err, req, res, next) => {
|
||||||
console.error(err);
|
if (err instanceof TokenError) {
|
||||||
error(res, "Server error", err.status || 500);
|
clientError(res, "Invalid code");
|
||||||
|
} else {
|
||||||
|
console.error(err);
|
||||||
|
error(res, "Server error", err.status || 500);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 404 response
|
// 404 response
|
||||||
|
|
Loading…
Add table
Reference in a new issue