calions-app/jsonapi-http/1.3.1

NOTE: the latest version is 1.4.2

Renamed to FabienHenon/jsonapi-http. It is published under that name, and new versions come out there.

Versions published as calions-app/jsonapi-http still install under that name. 8 versions of 9 come from the new location (see their notes). 1 version could not be recovered and cannot be installed.

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/FabienHenon/jsonapi-http.

What we checked: The repo moved to github.com/FabienHenon/jsonapi-http. Rebuilt with git archive from commit e5e177116b95 of https://github.com/FabienHenon/jsonapi-http (zip prefix calions-app-jsonapi-http-e5e1771/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 b822994db3c32a439805b0749580a38072d3650d.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/calions-app/jsonapi-http/zipball/1.3.1/

Http.Error

The Http.Error module defines a new kind of http error related to json api

Definitions

= HttpError Error
| JsonApiError (List Error)
| CustomError String

You can have:

  • HttpError: a normal http error
  • JsonApiError: an error related to the json api specification
  • CustomError: a custom error
type alias ErrorConfig =
{ httpErrorToString : Error -> String
, errorClass : Maybe String
, detailClass : Maybe String
}

Configuration used to display a RequestError

  • httpErrortoString is the function used to display a string from an http error
  • errorClass is an additionnal class you can add to the main container of the error
  • detailClass is an additionnal class you can add to children of the main container of the error

Functions

displayError : ErrorConfig -> RequestError -> Html msg

Displays a RequestError. You must provide a configuration to be able to display correctly any kind of error.

Errors are displayed like this:

<span class="error">
    <span class "error-detail error-detail-username1">Error on username</span>
    <span class "error-detail error-detail-password2">Error on password</span>
</span>
getErrorForField : String -> List Error -> Maybe String

Returns the jsonapi error message for the given field name

Let's say you have the following json api error:

{
   "errors":[
      {
         "detail":"Password should be at least 8 character(s)",
         "source":{
            "pointer":"/data/attributes/password"
         },
         "title":"should be at least 8 character(s)"
      }
   ],
   "jsonapi":{
      "version":"1.0"
   }
}

You can get the detail error message "Password should be at least 8 character(s)" like this:

getErrorForField "password" error
getJsonApiErrors : RequestError -> List ( String, String )

Retuens a list of the json api errors or an empty list if there is no error.

Let's say you have the following json api errors:

{
   "errors":[
      {
         "detail":"Password should be at least 8 character(s)",
         "source":{
            "pointer":"/data/attributes/password"
         },
         "title":"should be at least 8 character(s)"
      },
      {
         "detail":"Username must no be empty",
         "source":{
            "pointer":"/data/attributes/username"
         },
         "title":"should not be empty"
      }
   ],
   "jsonapi":{
      "version":"1.0"
   }
}

Calling getJsonApiErrors errors will return:

[ ( "password", "Password should be at least 8 character(s)" )
, ( "username", "Username must no be empty" )
]