@@ -25,15 +25,27 @@ defmodule GeoserverConfig.Styles do
2525 ## Example
2626 GeoserverConfig.Styles.list_styles()
2727 """
28- @ spec list_styles ( ) :: Req.Response . t ( )
29- def list_styles ( ) do
28+ @ spec list_styles ( ) :: { :ok , list ( ) } | { :error , any ( ) }
29+ def list_styles do
3030 url = "#{ @ base_url } /styles"
3131
32- Req . get! (
33- url ,
34- auth: { :basic , "#{ @ username } :#{ @ password } " } ,
35- headers: [ { "Accept" , "application/json" } ]
36- )
32+ case Req . get (
33+ url ,
34+ auth: { :basic , "#{ @ username } :#{ @ password } " } ,
35+ headers: [ { "Accept" , "application/json" } ]
36+ ) do
37+ { :ok , % { status: 200 , body: % { "styles" => % { "style" => styles } } } } when is_list ( styles ) ->
38+ { :ok , styles }
39+
40+ { :ok , % { status: 200 , body: % { "styles" => % { } } } } ->
41+ { :ok , [ ] }
42+
43+ { :ok , % { status: status , body: body } } ->
44+ { :error , { :http_error , status , body } }
45+
46+ { :error , reason } ->
47+ { :error , { :request_failed , reason } }
48+ end
3749 end
3850
3951 @ doc """
@@ -48,14 +60,27 @@ defmodule GeoserverConfig.Styles do
4860 ## Example
4961 GeoserverConfig.Styles.list_styles_workspace_specific("demo")
5062 """
63+ @ spec list_styles_workspace_specific ( String . t ( ) ) :: { :ok , list ( ) } | { :error , any ( ) }
5164 def list_styles_workspace_specific ( workspace ) do
5265 url = "#{ @ base_url } /workspaces/#{ workspace } /styles"
5366
54- Req . get! (
55- url ,
56- auth: { :basic , "#{ @ username } :#{ @ password } " } ,
57- headers: [ { "Accept" , "application/json" } ]
58- )
67+ case Req . get (
68+ url ,
69+ auth: { :basic , "#{ @ username } :#{ @ password } " } ,
70+ headers: [ { "Accept" , "application/json" } ]
71+ ) do
72+ { :ok , % { status: 200 , body: % { "styles" => % { "style" => styles } } } } when is_list ( styles ) ->
73+ { :ok , styles }
74+
75+ { :ok , % { status: 200 , body: % { "styles" => % { } } } } ->
76+ { :ok , [ ] }
77+
78+ { :ok , % { status: status , body: body } } ->
79+ { :error , { :http_error , status , body } }
80+
81+ { :error , reason } ->
82+ { :error , { :request_failed , reason } }
83+ end
5984 end
6085
6186 @ doc """
0 commit comments