Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geomag-algorithms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Geomagnetism Program
geomag-algorithms
Commits
0592b36c
Commit
0592b36c
authored
4 years ago
by
Jeremy M Fee
Browse files
Options
Downloads
Patches
Plain Diff
Add usage url to errors, clean up url output
parent
6cc972ae
No related branches found
Branches containing commit
Tags
1.3.4
Tags containing commit
1 merge request
!146
Release CMO metadata to production
Pipeline
#25996
passed with warnings
4 years ago
Stage: test
Stage: integration
Stage: scan
Stage: deploy
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
code.json
+1
-1
1 addition, 1 deletion
code.json
geomagio/api/ws/app.py
+16
-8
16 additions, 8 deletions
geomagio/api/ws/app.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
18 additions
and
10 deletions
code.json
+
1
−
1
View file @
0592b36c
...
...
@@ -3,7 +3,7 @@
"name"
:
"geomag-algorithms"
,
"organization"
:
"U.S. Geological Survey"
,
"description"
:
"Library for processing Geomagnetic timeseries data."
,
"version"
:
"1.3.
3
"
,
"version"
:
"1.3.
4
"
,
"status"
:
"Development"
,
"permissions"
:
{
...
...
This diff is collapsed.
Click to expand it.
geomagio/api/ws/app.py
+
16
−
8
View file @
0592b36c
import
os
from
typing
import
Dict
,
Union
from
fastapi
import
FastAPI
,
Request
,
Response
from
fastapi.exceptions
import
RequestValidationError
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.responses
import
JSONResponse
,
PlainTextResponse
,
RedirectResponse
from
obspy
import
UTCDateTime
...
...
@@ -78,13 +76,22 @@ def format_error(
status_code
:
int
,
exception
:
str
,
format
:
str
,
request
:
Request
)
->
Response
:
"""
Assign error_body value based on error format.
"""
# These urls are embedded in responses
# and app usually runs behind reverse proxy
url
=
str
(
request
.
url
)
usage
=
f
"
http://
{
request
.
headers
[
'
host
'
]
}
/ws/docs
"
if
"
x-forwarded-proto
"
in
request
.
headers
:
proto
=
f
"
{
request
.
headers
[
'
x-forwarded-proto
'
]
}
:
"
url
=
url
.
replace
(
"
http:
"
,
proto
)
usage
=
usage
.
replace
(
"
http:
"
,
proto
)
# serve error
if
format
==
"
json
"
:
return
json_error
(
status_code
,
exception
,
request
.
url
)
return
json_error
(
code
=
status_code
,
error
=
exception
,
url
=
url
,
usage
=
usage
)
else
:
return
text_error
(
status_code
,
exception
,
request
.
url
)
return
text_error
(
code
=
status_code
,
error
=
exception
,
url
=
url
,
usage
=
usage
)
def
json_error
(
code
:
int
,
error
:
Exception
,
url
:
str
)
->
Response
:
def
json_error
(
code
:
int
,
error
:
Exception
,
url
:
str
,
usage
:
str
)
->
Response
:
"""
Format json error message.
Returns
...
...
@@ -100,7 +107,8 @@ def json_error(code: int, error: Exception, url: str) -> Response:
"
status
"
:
code
,
"
error
"
:
str
(
error
),
"
generated
"
:
f
"
{
UTCDateTime
().
isoformat
()
}
Z
"
,
"
url
"
:
str
(
url
),
"
url
"
:
url
,
"
usage
"
:
usage
,
"
version
"
:
VERSION
,
},
},
...
...
@@ -108,7 +116,7 @@ def json_error(code: int, error: Exception, url: str) -> Response:
)
def
text_error
(
code
:
int
,
error
:
Exception
,
url
:
str
)
->
Response
:
def
text_error
(
code
:
int
,
error
:
Exception
,
url
:
str
,
usage
:
str
=
""
)
->
Response
:
"""
Format error message as plain text
Returns
...
...
@@ -120,7 +128,7 @@ def text_error(code: int, error: Exception, url: str) -> Response:
{
error
}
Usage details are available from
Usage details are available from
{
usage
}
Request:
{
url
}
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
0592b36c
...
...
@@ -9,7 +9,7 @@ if ssl_cert_file:
setuptools
.
setup
(
name
=
"
geomag-algorithms
"
,
version
=
"
1.3.
3
"
,
version
=
"
1.3.
4
"
,
description
=
"
USGS Geomag Algorithms Library
"
,
url
=
"
https://github.com/usgs/geomag-algorithms
"
,
packages
=
setuptools
.
find_packages
(
exclude
=
[
"
test*
"
]),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment