Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion npm-api-maker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kaspernj/api-maker",
"version": "1.0.394",
"version": "1.0.396",
"type": "module",
"description": "",
"main": "index.js",
Expand Down
11 changes: 11 additions & 0 deletions npm-api-maker/src/commands-pool.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,21 @@ export default class ApiMakerCommandsPool {
commandData.resolve(commandResponseData)
} else if (responseType == "error") {
const error = new CustomError("Command error", {response: commandResponseData})
const backendBacktrace = commandResponse.data.errors[0].backtrace
let stacktrace = error.stack.split("\n")
const stacktraceErrorMessage = stacktrace[0]

stacktrace = stacktrace.slice(1, stacktrace.length - 1)

if (backendBacktrace) {
error.stack = [stacktraceErrorMessage].concat(backendBacktrace.map((trace) => ` at ${trace}`)).concat(stacktrace).join("\n")
}

error.stack += "\n"
error.stack += commandData.stack.split("\n").slice(1).join("\n")

// throw new Error(`Stack is: ${JSON.stringify(error.stack.split("\n"), null, 2)}`)

commandData.reject(error)
} else if (responseType == "failed") {
this.handleFailedResponse(commandData, commandResponseData)
Expand Down
6 changes: 6 additions & 0 deletions npm-api-maker/src/form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class FormInputs {
return result
}

get(name) {
if (!(name in this.inputs)) throw new Error(`Input '${name}' not found`)

return this.inputs[name]
}

setValue(name, value) {
if (!name) throw new Error("'name' is required")

Expand Down
9 changes: 6 additions & 3 deletions npm-api-maker/src/inputs/input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ const ApiMakerInputsInput = memo(shapeComponent(class ApiMakerInputsInput extend
}

setup() {
const {inputProps} = this.p
const {defaultValue, name} = inputProps

this.form = useForm()
this.visibleInputRef = useRef()

this.useStates({
blankInputName: digg(this, "props", "inputProps", "type") == "file"
blankInputName: digg(inputProps, "type") == "file"
})
useMemo(() => {
if ("defaultValue" in this.props) {
this.tt.form?.setValue(this.props.defaultValue)
if (name) {
this.tt.form?.setValue(name, defaultValue)
}
}, [])
}
Expand Down
2 changes: 0 additions & 2 deletions npm-api-maker/src/super-admin/edit-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ export default memo(shapeComponent(class ApiMakerSuperAdminEditPage extends Base
const {model} = this.tt
const formObject = this.s.form.asObject()

console.log({formObject})

model.assignAttributes(formObject)
await model.save()
Params.changeParams({mode: undefined, model_id: model.id()})
Expand Down
4 changes: 3 additions & 1 deletion npm-api-maker/src/use-updated-event.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import debounceFunction from "debounce"
import ModelEvents from "./model-events.mjs"
import useShape from "set-state-compare/src/use-shape.js"

const apiMakerUseUpdatedEvent = (model, onUpdated, {active = true, debounce, onConnected, ...restProps}) => {
const apiMakerUseUpdatedEvent = (model, onUpdated, props = {}) => {
const {active = true, debounce, onConnected, ...restProps} = props

if (Object.keys(restProps).length > 0) {
throw new Error(`Unknown props given to useUpdatedEvent: ${Object.keys(restProps).join(", ")}`)
}
Expand Down
8 changes: 7 additions & 1 deletion ruby-gem/app/services/api_maker/base_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ def self.run_command(collection:, command_id:, command_data:, command_response:,
rescue => e # rubocop:disable Style/RescueStandardError
error_response = {
success: false,
errors: [{message: command_error_message(e), type: :runtime_error}]
errors: [
{
backtrace: Rails.env.development? || Rails.env.test? ? Rails.backtrace_cleaner.clean(e.backtrace) : nil,
message: command_error_message(e),
type: :runtime_error
}
]
}

Rails.logger.error e.message
Expand Down
9 changes: 7 additions & 2 deletions ruby-gem/app/services/api_maker/collection_command_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ def perform
commands.each_key do |command_id|
command_response.error_for_command(
command_id,
success: false,
errors: [e.message]
errors: [
{
backtrace: Rails.env.development? || Rails.env.test? ? Rails.backtrace_cleaner.clean(Rails.e.backtrace) : nil,
message: e.message
}
],
success: false
)
end

Expand Down