I’m having a little problem. There is a function, which is the result of a json.
I want to get my Phoenix to show the error on the screen and redirect to a specific place.
If status_code for 201, appears on screen
“Successfully Inserted”
Can you help me?
Below you show what I did …
response =
%HTTPoison.Response{
body: “{"errors":[{"code":"CUS-008","path":"customer.ownId","description":"-----------ERROR ---------"}]}”,
headers: [
{“Server”, “nginx”},
{“Date”, “Wed, 21 Aug 2019 23:16:00 GMT”},
{“Content-Type”, “application/json”},
{“Content-Length”, “166”},
{“Connection”, “keep-alive”},
{“X-Content-Type-Options”, “nosniff”},
{“Vary”, “Accept-Encoding, Origin”}
],
request: %HTTPoison.Request{
body: “{"taxDocument":{"type":"CPF","number":"00000000000"},"shippingAddress":{"zipCode":"75000000","streetNumber":"1","street":"Rua 6","state":"Minas","district":"Vila Sales","country":"BRA","city":"Minas Gerais"},"phone":{"number":"999999999","countryCode":"55","areaCode":"11"},"ownId":"24","fullname":"Name test full","email":"test15@test.com.br","birthDate":"1980-12-09"}”,
headers: [
{“Authorization”,
“Basic ghghghtyty5==”},
{“Content-Type”, “application/json”}
],
method: :post,
options: [
hackney: [
basic_auth: {“12345”,
“12345”}
]
],
params: %{},
url: “https://teste.teste.com.br/v2/customers/”
},
request_url: “https://teste.teste.com.br/v2/customers/”,
status_code: 400
}
Controller =
case Floki.find(response.body, "code") do
[{"code", _, [code]}] ->
code
body ->
raise """
status: #{response.status_code}
"""
end