This repository was archived by the owner on Sep 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
Error handling is not working correctly for Postgres #130
Copy link
Copy link
Closed
Description
Issue
My user model requires emails to be unique. If I try to create a user with a duplicate email address I get a 500 error with the DB error as the message.
GeneralError: insert into "users" ("created_on", "email", "isVerified", "name", "password", "updated_on", "verifyChanges", "verifyExpires", "verifyShortToken", "verifyToken") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) returning "id" - duplicate key value violates unique constraint "users_email_unique"
Debugging
I've been trying to debug in error-handler.js. It looks like this error just isn't being handled. The incoming error object has all the necessary info to return a well formed Feathers error, but it's not doing anything.
Code
I have a very simple user service that looks like this:
users.service.ts
// Initializes the `user` service on path `/user`
import { ServiceAddons } from '@feathersjs/feathers';
import { Application } from '../../declarations';
import Users from './users.class';
import UserModel, { UserType } from '../../models/user.model';
import hooks from './users.hooks';
// Add this service to the service type index
declare module '../../declarations' {
interface ServiceTypes {
users: Users & ServiceAddons<UserType>;
}
}
export default function (app: Application) {
const options = {
Model: UserModel,
paginate: app.get('paginate'),
};
// Initialize our service with any options it requires
app.use('/users', new Users(options, app));
// Get our initialized service so that we can register hooks
const service = app.service('users');
service.hooks(hooks);
}users.class.ts
import UserModel, { UserType } from '../../models/user.model';
import Base from '../base.class';
export default class Users extends Base<UserType, UserModel> {}base.class is very simple and is simply extending feathers-objection.Service with some extra typing.
Dependencies
{
"feathers-objection": "^6.1.1",
"objection": "^2.2.3",
"pg": "^8.4.1",
"knex": "^0.21.6",
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels