mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-09-11 15:26:19 +03:00
Fixes HttpError and AuthError instanceof bug (#1648)
This commit is contained in:
parent
a35040e351
commit
66682ff568
@ -10,6 +10,7 @@
|
||||
},
|
||||
"exports": {
|
||||
"./core/HttpError": "./core/HttpError.js",
|
||||
"./core/AuthError": "./core/AuthError.js",
|
||||
"./core/config": "./core/config.js",
|
||||
"./core/stitches.config": "./core/stitches.config.js",
|
||||
"./core/storage": "./core/storage.ts",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import express from 'express'
|
||||
|
||||
import HttpError from './core/HttpError.js'
|
||||
import HttpError from 'wasp/core/HttpError'
|
||||
import indexRouter from './routes/index.js'
|
||||
|
||||
// TODO: Consider extracting most of this logic into createApp(routes, path) function so that
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
import { ensureValidEmail } from "../../validation.js";
|
||||
import type { EmailFromField } from '../../../email/core/types.js';
|
||||
import { GetPasswordResetEmailContentFn } from './types.js';
|
||||
import HttpError from '../../../core/HttpError.js';
|
||||
import HttpError from 'wasp/core/HttpError'
|
||||
|
||||
export function getRequestPasswordResetRoute({
|
||||
fromField,
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
} from "../../utils.js";
|
||||
import { ensureTokenIsPresent, ensurePasswordIsPresent, ensureValidPassword } from "../../validation.js";
|
||||
import { tokenVerificationErrors } from "./types.js";
|
||||
import HttpError from '../../../core/HttpError.js';
|
||||
import HttpError from 'wasp/core/HttpError';
|
||||
|
||||
export async function resetPassword(
|
||||
req: Request<{ token: string; password: string; }>,
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
import { ensureValidEmail, ensureValidPassword, ensurePasswordIsPresent } from "../../validation.js";
|
||||
import { GetVerificationEmailContentFn } from './types.js';
|
||||
import { validateAndGetUserFields } from '../../utils.js'
|
||||
import HttpError from '../../../core/HttpError.js';
|
||||
import HttpError from 'wasp/core/HttpError';
|
||||
import { type UserSignupFields } from '../types.js';
|
||||
|
||||
export function getSignupRoute({
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
deserializeAndSanitizeProviderData,
|
||||
} from '../../utils.js';
|
||||
import { tokenVerificationErrors } from './types.js';
|
||||
import HttpError from '../../../core/HttpError.js';
|
||||
import HttpError from 'wasp/core/HttpError';
|
||||
|
||||
|
||||
export async function verifyEmail(
|
||||
|
@ -1,8 +1,8 @@
|
||||
{{={= =}=}}
|
||||
import { hashPassword } from './password.js'
|
||||
import { verify } from './jwt.js'
|
||||
import AuthError from '../core/AuthError.js'
|
||||
import HttpError from '../core/HttpError.js'
|
||||
import AuthError from 'wasp/core/AuthError'
|
||||
import HttpError from 'wasp/core/HttpError'
|
||||
import prisma from '../dbClient.js'
|
||||
import { sleep } from '../utils.js'
|
||||
import {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import HttpError from '../core/HttpError.js';
|
||||
import HttpError from 'wasp/core/HttpError'
|
||||
|
||||
export const PASSWORD_FIELD = 'password';
|
||||
const USERNAME_FIELD = 'username';
|
||||
|
@ -1,17 +0,0 @@
|
||||
class AuthError extends Error {
|
||||
constructor (message, data, ...params) {
|
||||
super(message, ...params)
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, AuthError)
|
||||
}
|
||||
|
||||
this.name = this.constructor.name
|
||||
|
||||
if (data) {
|
||||
this.data = data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default AuthError
|
@ -1,22 +0,0 @@
|
||||
class HttpError extends Error {
|
||||
constructor (statusCode, message, data, ...params) {
|
||||
super(message, ...params)
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, HttpError)
|
||||
}
|
||||
|
||||
this.name = this.constructor.name
|
||||
|
||||
if (!(Number.isInteger(statusCode) && statusCode >= 400 && statusCode < 600)) {
|
||||
throw new Error('statusCode has to be integer in range [400, 600).')
|
||||
}
|
||||
this.statusCode = statusCode
|
||||
|
||||
if (data) {
|
||||
this.data = data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default HttpError
|
@ -221,8 +221,6 @@ genSrcDir :: AppSpec -> Generator [FileDraft]
|
||||
genSrcDir spec =
|
||||
sequence
|
||||
[ genFileCopy [relfile|app.js|],
|
||||
genFileCopy [relfile|core/AuthError.js|],
|
||||
genFileCopy [relfile|core/HttpError.js|],
|
||||
genDbClient spec,
|
||||
genConfigFile spec,
|
||||
genServerJs spec,
|
||||
|
Loading…
Reference in New Issue
Block a user