fix: better validation error messages (#3736)
This commit is contained in:
@@ -109,7 +109,7 @@ def register_exception_handlers(app: FastAPI): # noqa: C901
|
||||
logger.error(f"RequestValidationError: {exc!s}")
|
||||
return render_html_error(request, exc) or JSONResponse(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
content={"detail": str(exc)},
|
||||
content={"detail": [dict(e) for e in exc.errors()]},
|
||||
)
|
||||
|
||||
@app.exception_handler(HTTPException)
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+29
-11
@@ -114,6 +114,13 @@ window._lnbitsUtils = {
|
||||
formatMsat(value) {
|
||||
return this.formatSat(value / 1000)
|
||||
},
|
||||
parseJSONSafe(str) {
|
||||
try {
|
||||
return JSON.parse(str)
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
},
|
||||
notifyApiError(error) {
|
||||
if (!error.response) {
|
||||
return console.error(error)
|
||||
@@ -123,17 +130,28 @@ window._lnbitsUtils = {
|
||||
401: 'warning',
|
||||
500: 'negative'
|
||||
}
|
||||
Quasar.Notify.create({
|
||||
timeout: 5000,
|
||||
type: types[error.response.status] || 'warning',
|
||||
message:
|
||||
error.response.data.message || error.response.data.detail || null,
|
||||
caption:
|
||||
[error.response.status, ' ', error.response.statusText]
|
||||
.join('')
|
||||
.toUpperCase() || null,
|
||||
icon: null
|
||||
})
|
||||
let messages = error.response.data.detail
|
||||
if (messages) {
|
||||
messages = Array.isArray(messages)
|
||||
? messages.map(e => e.msg + ` (${e.loc?.join('/')})`)
|
||||
: (messages = [messages])
|
||||
} else {
|
||||
messages = [error.response.data.message || error.response.data.detail]
|
||||
}
|
||||
|
||||
messages.forEach(message =>
|
||||
Quasar.Notify.create({
|
||||
timeout: 5000,
|
||||
type: types[error.response.status] || 'warning',
|
||||
message,
|
||||
caption:
|
||||
[error.response.status, ' ', error.response.statusText]
|
||||
.join('')
|
||||
.toUpperCase() || null,
|
||||
icon: null,
|
||||
closeBtn: true
|
||||
})
|
||||
)
|
||||
},
|
||||
search(data, q, field, separator) {
|
||||
try {
|
||||
|
||||
@@ -245,7 +245,7 @@ async def test_create_invoice_validates_used_currency(
|
||||
)
|
||||
assert response.status_code == 400
|
||||
res_data = response.json()
|
||||
assert "The provided unit is not supported" in res_data["detail"]
|
||||
assert "The provided unit is not supported" in res_data["detail"][0]["msg"]
|
||||
|
||||
|
||||
# check POST /api/v1/payments: invoice creation for internal payments only
|
||||
@@ -823,7 +823,7 @@ async def test_api_payments_pay_lnurl(client, adminkey_headers_from):
|
||||
"/api/v1/payments/lnurl", json=lnurl_data, headers=adminkey_headers_from
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert "value_error.url.scheme" in response.json()["detail"]
|
||||
assert "invalid or missing URL scheme" in response.json()["detail"][0]["msg"]
|
||||
|
||||
|
||||
################################ Labels ################################
|
||||
|
||||
@@ -2044,5 +2044,6 @@ async def test_api_update_user_labels(http_client: AsyncClient):
|
||||
assert response.status_code == 400
|
||||
data = response.json()
|
||||
assert (
|
||||
"""string does not match regex "([A-Za-z0-9 ._-]{1,100}$)""" in data["detail"]
|
||||
"""string does not match regex "([A-Za-z0-9 ._-]{1,100}$)"""
|
||||
in data["detail"][0]["msg"]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user