Skip to content

[4.x]: 400 Error on "save-user" controller (AJAX) #15170

@zadro

Description

@zadro

What happened?

When saving a user profile via Ajax to the "save-user" endpoint, a status code 200 is returned when there are no errors. All good here.

However, the controller returns with a 400 status code if any field returns an error.

JSON data is returned in either event, so this behavior appears to be a bug.

Response from NON field error (200 status):

{
	"id": 1,
	"modelName": "user",
	"user": {
		.....
	},
	"message": "User saved."
}

Response with any field error (400 status):

{
	"modelName": "user",
	"user": {
		.....
	},
	"errors": {
		"currentPassword": [
			"Incorrect current password."
		],
		"newPassword": [
			"New Password should contain at least 6 characters."
		]
	},
	"message": "Couldn’t save user."
}

My Ajax uses jQuery and a basic $.post(); method.

Please let me know if there's anything else I can provide.

Craft CMS version

4.9.6

PHP version

8.2.20

Operating system and version

Linux 6.1.0-18-amd64

Database type and version

MariaDB 10.11.8

Image driver and version

No response

Installed plugins and versions

CKEditor 3.8.3
Super Table 3.0.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions