Skip to content

Commit

Permalink
fix(opapi): get real error message (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy authored Aug 20, 2024
1 parent 5e4dddd commit d760b1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion opapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bpinternal/opapi",
"version": "0.10.20",
"version": "0.10.21",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
12 changes: 11 additions & 1 deletion opapi/src/handler-generator/export-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs/promises'

const CONTENT = `import qs from 'qs'
import { isAxiosError } from 'axios'
import { isApiError } from './errors'
import * as types from './typings'
Expand Down Expand Up @@ -101,7 +102,16 @@ export class Router {
}
const getErrorBody = (thrown: unknown) => {
if (thrown instanceof Error) {
if (isAxiosError(thrown)) {
const data = thrown.response?.data
const statusCode = thrown.response?.status
if (!data) {
return \`\${err.message} (no response data) (Status Code: \${statusCode})\`
}
return \`\${data.message || data.error?.message || data.error || data.body || err.message} (Status Code: \${statusCode})\`
} else if (thrown instanceof Error) {
return thrown.message
}
try {
Expand Down

0 comments on commit d760b1d

Please sign in to comment.