Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active February 27, 2016 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ericelliott/94cb04b9b4b575ff413b to your computer and use it in GitHub Desktop.
Save ericelliott/94cb04b9b4b575ff413b to your computer and use it in GitHub Desktop.
Siren Error Extension Proposal
{
"class": [
"error",
"UnprocessableEntity",
"api"
],
"properties": {
"message": "Unprocessable entity. The submission failed resource validation.",
"code": 422
},
"entities": [
{
"class": [
"error",
"validation",
"maxlength"
],
"properties": {
"message": "The maximum length is 64 characters.",
"id": "title"
}
},
{
"class": [
"error",
"validation",
"pattern"
],
"properties": {
"message": "The list price must be a valid US currency.",
"id": "listPrice"
}
}
],
"actions": [
{
"name": "retry",
"href": "/albums",
"method": "POST",
"fields": [
{
"type": "text",
"name": "title",
"maxLength": 64
},
{
"type": "number",
"name": "listPrice",
"pattern": "[+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\\.[0-9]{2})?"
}
]
}
],
"links": [
{
"rel": [
"index"
],
"href": "/albums"
}
]
}
@ericelliott
Copy link
Author

I like that @eric. How about also including the POST/PATCH/PUT parameters as properties?

Echoing back user inputs can result in exploitable attack vectors. I'd advise people to check the server logs for debugging.

@ericelliott
Copy link
Author

Gist updated.

@ericelliott
Copy link
Author

A more compact version utilizing the non-standard entityAttributes:

{
    "class": [
        "error",
        "UnprocessableEntity",
        "api"
    ],
    "properties": {
        "message": "Unprocessable entity. The submission failed resource validation.",
        "code": 422
    },
    "entityAttributes": {
        "class": [
            "error",
            "validation",
            "maxlength"
        ]
    },
    "entities": [
        {
            "properties": {
                "message": "The maximum length is 64 characters.",
                "id": "title"
            }
        },
        {
            "properties": {
                "message": "The list price must be a valid US currency.",
                "id": "listPrice"
            }
        }
    ],
    "actions": [
        {
            "name": "retry",
            "href": "/albums",
            "method": "POST",
            "fields": [
                {
                    "type": "text",
                    "name": "title",
                    "maxLength": 64
                },
                {
                    "type": "number",
                    "name": "listPrice",
                    "pattern": "[+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\\.[0-9]{2})?"
                }
            ]
        }
    ],
    "links": [
        {
            "rel": [
                "index"
            ],
            "href": "/albums"
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment