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

Problem Details for HTTP APIs (v11.2.5) #1336

Merged
merged 2 commits into from
Aug 12, 2019
Merged

Problem Details for HTTP APIs (v11.2.5) #1336

merged 2 commits into from
Aug 12, 2019

Conversation

kataras
Copy link
Owner

@kataras kataras commented Aug 12, 2019

Example Code:

func newProductProblem(productName, detail string) iris.Problem {
    return iris.NewProblem().
        // The type URI, if relative it automatically convert to absolute.
        Type("/product-error"). 
        // The title, if empty then it gets it from the status code.
        Title("Product validation problem").
        // Any optional details.
        Detail(detail).
        // The status error code, required.
        Status(iris.StatusBadRequest).
        // Any custom key-value pair.
        Key("productName", productName)
        // Optional cause of the problem, chain of Problems.
        // .Cause(other iris.Problem)
}

func fireProblem(ctx iris.Context) {
    ctx.Problem(newProductProblem("product name", "problem error details"))
}
{
  "type": "https://host.domain/product-error",
  "status": 400,
  "title": "Product validation problem",
  "detail": "problem error details",
  "productName": "product name"
}

@kataras kataras merged commit e516549 into master Aug 12, 2019
@kataras kataras deleted the v11.2.5 branch August 12, 2019 09:13
github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this pull request Jul 27, 2020
Former-commit-id: 25fa9484d0561f669cd94453a6ea5d156b6997cb
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

Successfully merging this pull request may close these issues.

None yet

1 participant