v10.0.0-rc32
parent
e1f79aeaf5
commit
70b5fb18bb
|
@ -6,6 +6,7 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
import API.View, only: [render: 2]
|
import API.View, only: [render: 2]
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
require FarmbotCore.Logger
|
||||||
use GenServer
|
use GenServer
|
||||||
@timeout 1500
|
@timeout 1500
|
||||||
|
|
||||||
|
@ -53,10 +54,12 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
case http_request(dirty, module) do
|
case http_request(dirty, module) do
|
||||||
# Valid data
|
# Valid data
|
||||||
{:ok, %{status: s, body: body}} when s > 199 and s < 300 ->
|
{:ok, %{status: s, body: body}} when s > 199 and s < 300 ->
|
||||||
|
FarmbotCore.Logger.error(2, "HTTP #{s} OK. #{inspect(body)}")
|
||||||
dirty |> module.changeset(body) |> handle_changeset(module)
|
dirty |> module.changeset(body) |> handle_changeset(module)
|
||||||
|
|
||||||
# Invalid data
|
# Invalid data
|
||||||
{:ok, %{status: s, body: %{} = body}} when s > 399 and s < 500 ->
|
{:ok, %{status: s, body: %{} = body}} when s > 399 and s < 500 ->
|
||||||
|
FarmbotCore.Logger.error(2, "HTTP Error #{s}. #{inspect(body)}")
|
||||||
changeset = module.changeset(dirty)
|
changeset = module.changeset(dirty)
|
||||||
|
|
||||||
Enum.reduce(body, changeset, fn {key, val}, changeset ->
|
Enum.reduce(body, changeset, fn {key, val}, changeset ->
|
||||||
|
@ -66,13 +69,14 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
|
|
||||||
# Invalid data, but the API didn't say why
|
# Invalid data, but the API didn't say why
|
||||||
{:ok, %{status: s, body: _body}} when s > 399 and s < 500 ->
|
{:ok, %{status: s, body: _body}} when s > 399 and s < 500 ->
|
||||||
|
FarmbotCore.Logger.error(2, "HTTP Error #{s}. #{inspect(dirty)}")
|
||||||
module.changeset(dirty)
|
module.changeset(dirty)
|
||||||
|> Map.put(:valid?, false)
|
|> Map.put(:valid?, false)
|
||||||
|> handle_changeset(module)
|
|> handle_changeset(module)
|
||||||
|
|
||||||
# HTTP Error. (500, network error, timeout etc.)
|
# HTTP Error. (500, network error, timeout etc.)
|
||||||
error ->
|
error ->
|
||||||
Logger.error(
|
FarmbotCore.Logger.error(2,
|
||||||
"[#{module} #{dirty.local_id} #{inspect(self())}] HTTP Error: #{module} #{
|
"[#{module} #{dirty.local_id} #{inspect(self())}] HTTP Error: #{module} #{
|
||||||
inspect(error)
|
inspect(error)
|
||||||
}"
|
}"
|
||||||
|
|
Loading…
Reference in New Issue