Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating contentTypes programmatically gives generic error messages #2257

Open
danieljameswilliams opened this issue Apr 22, 2024 · 0 comments

Comments

@danieljameswilliams
Copy link

We are trying to update an existing contentType programmatically using the contentful-management SDK, but when there are conflicts of some sort, we don't get any meaningful error messages. The response would often be a 409 - Conflict - and then the JSON tried to process

What we would expect is some kind of detailed explanation of the error, so we can resolve it. We believe this is a quite important feature, because when migrating contentTypes, if anything fails we have to delete all content to start over, which isn't an option when we go live.

In an attempt to figure out the error I deleted the contentType from the web interface and tried to deploy again, and here it gave a meaningful error: 422 - Unprocessable Entity - Field "X" mapped multiple times in "editorLayout"

export async function updateContentType(environment: Contentful.Environment, config: ContentTypeDefinition) {
  const contentType = await environment.getContentType(config.id)
  if (contentType) {
    contentType.name = config.name
    contentType.displayField = config.displayField
    contentType.description = config.description
    contentType.fields = config.fields

    const updatedContentType = await contentType.update()
    const publishedContentType = await updatedContentType.publish()
    const editorInterface = await publishedContentType.getEditorInterface()
    editorInterface.controls = config.controls
    editorInterface.editorLayout = config.editorLayout
    editorInterface.groupControls = config.groupControls
    await editorInterface.update()
  }
}
{
  "VersionMismatch": {
    "status": 409,
    "statusText": "Conflict",
    "message": "",
    "details": {},
    "request": {
      "url": "/spaces/X/environments/dev/content_types/X",
      "headers": {
        "Accept": "application/json, text/plain, */*",
        "Content-Type": "application/vnd.contentful.management.v1+json",
        "X-Contentful-User-Agent": "sdk contentful-management.js/11.25.0; platform node.js/v21.7.3; os Windows/v21.7.3;",
        "Authorization": "Bearer X",
        "User-Agent": "axios/1.6.8",
        "Content-Length": "1726",
        "Accept-Encoding": "gzip, compress, deflate, br"
      },
      "method": "put",
      "payloadData": "X"
    },
    "requestId": "X"
  }
}

We are using "contentful-management": "^11.25.0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant