Exception: Takagi::Errors::RouteError

Inherits:
TakagiError
  • Object
show all
Defined in:
lib/takagi/errors.rb

Overview

Raised when route operations fail

Instance Attribute Summary

Attributes inherited from TakagiError

#context, #suggestions

Class Method Summary collapse

Methods inherited from TakagiError

#initialize

Constructor Details

This class inherits a constructor from Takagi::Errors::TakagiError

Class Method Details

.duplicate_route(method, path, existing_receiver) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/takagi/errors.rb', line 302

def self.duplicate_route(method, path, existing_receiver)
  new(
    "Route already defined: #{method} #{path}",
    context: {
      method: method,
      path: path,
      existing_receiver: existing_receiver.name
    },
    suggestions: [
      "Each path can only have one handler per method",
      "Use different paths: #{method} #{path}/v2 or #{method} #{path}/alt",
      "Or use route parameters: #{method} #{path}/:version"
    ]
  )
end

.invalid_path(path, reason) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/takagi/errors.rb', line 318

def self.invalid_path(path, reason)
  new(
    "Invalid route path: #{path.inspect}",
    context: {
      path: path,
      reason: reason
    },
    suggestions: [
      "Paths must start with '/'",
      "Example: get '/sensors/:id' do; end",
      "Parameters use colon syntax: ':id', ':name'"
    ]
  )
end

.missing_handler(method, path) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/takagi/errors.rb', line 333

def self.missing_handler(method, path)
  new(
    "No handler block provided for #{method} #{path}",
    context: {
      method: method,
      path: path
    },
    suggestions: [
      "Provide a block:",
      "  #{method.downcase} '#{path}' do",
      "    { message: 'Hello!' }",
      "  end"
    ]
  )
end