# Unhandled 422 error when posting new object

**URL:** https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762
**Category:** Help me!
**Created:** [July 30, 2020, 10:58pm UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762 "2020-07-30T22:58:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![theo744](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@theo744](https://community.forestadmin.com/u/theo744)
#### Post date: [July 30, 2020, 10:58pm UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/1 "2020-07-30T22:58:39Z")

</div>

Hi,

I get a 422 error when posting a new object with an undhandled rejection exception:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/1X/59d60d1918372d4edd81ad0687ffe0d9bfda0c89.png)

How do you debug those unhandled errors ?

---

<div class="post-metadata">

### Author: ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)
#### Post date: [July 31, 2020, 8:17am UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/2 "2020-07-31T08:17:15Z")

</div>

Hi @theo744

A 422 error relates to an invalid request.  
Anyway, we should never have unhandled rejection errors.

What were you doing when this error happened?

---

<div class="post-metadata">

### Author: ![theo744](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@theo744](https://community.forestadmin.com/u/theo744)
#### Post date: [July 31, 2020, 10:10am UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/3 "2020-07-31T10:10:45Z")

</div>

Hi @Sliman_Medini,

It happens on instruction

```javascript
recordCreator.create(recordToCreate)

```

in the post route of an Object. Same error happens when I replace my custom post method with the default one.

Is it possible to get log of those errors to understand what goes wrong with the request? It’s weird because updating the same object works fine

---

<div class="post-metadata">

### Author: ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)
#### Post date: [July 31, 2020, 10:16am UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/4 "2020-07-31T10:16:42Z")

</div>

> [@theo744](#):
>
> Same error happens when I replace my custom post method with the default one.

Ok so, we will consider the default one for the moment.  
It means, when you create a new record from Forest UI, you face this 422 error?  
Does this happen with all your models? If not can you share the structure of the failing model please.

Can you share an HAR with the traffic that cause the problem? (An HAR can be created by right-clicking in the request list of the request tab of the Chrome dev tools)

I need to reproduce the issue to handle it.

---

<div class="post-metadata">

### Author: ![theo744](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@theo744](https://community.forestadmin.com/u/theo744)
#### Post date: [July 31, 2020, 10:22pm UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/5 "2020-07-31T22:22:00Z")

</div>

Hi,

Yes, it happens when creating new record from UI. I only have this error with customers, my other objects work fine.

Here’s the configuration of my Customer:

```javascript
const Customer = sequelize.define('customer', {
    idCustomer: {
      type: DataTypes.INTEGER,
      primaryKey: true,
			autoIncrement: true,
    },
	idAddress: {
		type: DataTypes.INTEGER,
		allowNull: true,
	    defaultValue: null,
	    validate: {
			customValidator(value) {
				if((value == null) || (value == 0))
					throw new Error("L'adresse doit être renseignée");
			}
	    }
	},
    email: {
      type: DataTypes.STRING,
			allowNull: true,
			defaultValue: null,
			unique: true,
			validate: {
			isEmail: true,
			customValidator(value) {
				if(value === null)
					throw new Error("L'adresse email doit être renseignée");
			}
	  }
    },
    passwd: {
      type: DataTypes.STRING,
    },
    secureKey: {
      type: DataTypes.STRING,
    },
    dateAdd: {
      type: DataTypes.DATE,
    },
    dateUpd: {
      type: DataTypes.DATE,
    },
    active: {
      type: DataTypes.BOOLEAN,
	  defaultValue: true
    },
    deleted: {
      type: DataTypes.INTEGER,
    },
  }

```

You can find attached my customer.js file and the har of the post request. It seems the error might be relative to the address relationship because if I delete it, I can create the customer just fine.

[app.forestadmin.com\_Archive [20-08-01 00-10-37].har](https://community.forestadmin.com/uploads/short-url/vJTuGvCgXTfNkJsggTquM1rMZSq.har) (10.5 KB)

---

<div class="post-metadata">

### Author: ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)
#### Post date: [August 3, 2020, 8:29am UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/6 "2020-08-03T08:29:40Z")

</div>

Hi @theo744,

Following the code of `forest-express-sequelize`, it seems like the only way to trigger a 422 from `resource-creator.js` is with an invalid model. (This is visible [here](https://github.com/ForestAdmin/forest-express-sequelize/blob/master/src/services/resource-creator.js#L26)). I still find this concerning since you should have a valid error message, but I’m currently not able to reproduce

A workaround to debug this would be to add logs inside `node_modules/forest-express-sequelize/services/resource-creator.js`, or a debug log of the request body inside the route that fails, just to be sure that your model is valid.

I can see in your code (Not sure that really matters) that `customValidator` is using `==` to compare instead of the more usual `===`. I can’t be sure that is the source of the issue, but I would suggest to give this a try.

Sadly, in the provided HAR, I can’t see any HTTP 422 😕

---

<div class="post-metadata">

### Author: ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)
#### Post date: [September 20, 2021, 11:58am UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/7 "2021-09-20T11:58:48Z")

</div>

Hi @theo744 ,

Do you still experience this issue ?

---

<div class="post-metadata">

### Author: ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)
#### Post date: [October 21, 2021, 9:23am UTC](https://community.forestadmin.com/t/unhandled-422-error-when-posting-new-object/762/8 "2021-10-21T09:23:39Z")

</div>


