Skip to content
Permalink
Browse files

Add params_invalid error type

  • Loading branch information...
Hentioe committed Mar 13, 2019
1 parent d6243f2 commit 181526b72fe5825272cb4d1447afb8f249a9cf62
Showing with 12 additions and 10 deletions.
  1. +2 −1 apps/web_server/lib/web_server/result.ex
  2. +9 −8 apps/web_server/lib/web_server/router.ex
  3. +1 −1 apps/web_server/mix.exs
@@ -16,7 +16,8 @@ defmodule WebServer.Result do
header_invalid: 8001,
not_found: 7002,
params_deficiency: 6001,
params_conflict: 6003
params_conflict: 6003,
params_invalid: 6002
def error_code(reason_type) do
@errors[reason_type] || @errors[:general]
end
@@ -48,6 +48,9 @@ defmodule WebServer.Router do
unquote(import_schema_status_macro())

def fetch_paging_params(conn) do
alias WebServer.Error
import WebServer.Error

alias WebServer.Config.Store, as: ConfigStore
default_limit = ConfigStore.get(:web_server, :default_limit)
max_limit = ConfigStore.get(:web_server, :max_limit)
@@ -57,17 +60,15 @@ defmodule WebServer.Router do
limit = Map.get(conn.params, "limit", "#{default_limit}")

offset =
try do
String.to_integer(offset)
rescue
_ in ArgumentError -> 0
case Integer.parse(offset) do
:error -> raise Error, error(:params_invalid, "'offset' is not a valid number")
{n, _} -> n
end

limit =
try do
String.to_integer(limit)
rescue
_ in ArgumentError -> default_limit
case Integer.parse(limit) do
:error -> raise Error, error(:params_invalid, "'limit' is not a valid number")
{n, _} -> n
end

limit = if limit > max_limit, do: max_limit, else: limit
@@ -1,7 +1,7 @@
defmodule WebServer.MixProject do
use Mix.Project

@version "0.10.3"
@version "0.10.4-dev"

def project do
[

0 comments on commit 181526b

Please sign in to comment.
You can’t perform that action at this time.