@@ -30,6 +30,23 @@ def self.parse(input, options = {})
3030 end
3131
3232 class Error < StandardError
33+ # The status code associated with this error
34+ attr_reader :code
35+
36+ ##
37+ # Initializes a new patch error instance.
38+ #
39+ # @param [String, #to_s] message
40+ # @param [Hash{Symbol => Object}] options
41+ # @option options [Integer] :code (422)
42+ def initialize ( message , options = { } )
43+ @code = options . fetch ( :status_code , 422 )
44+ super ( message . to_s )
45+ end
46+ end
47+
48+ # Indicates bad syntax found in LD Patch document
49+ class ParserError < Error
3350 ##
3451 # The invalid token which triggered the error.
3552 #
@@ -41,17 +58,19 @@ class Error < StandardError
4158 #
4259 # @return [Integer]
4360 attr_reader :lineno
61+
4462 ##
45- # Initializes a new lexer error instance.
63+ # Initializes a new parser error instance.
4664 #
4765 # @param [String, #to_s] message
4866 # @param [Hash{Symbol => Object}] options
4967 # @option options [String] :token (nil)
5068 # @option options [Integer] :lineno (nil)
69+ # @option options [Integer] :code (400)
5170 def initialize ( message , options = { } )
5271 @token = options [ :token ]
5372 @lineno = options [ :lineno ] || ( @token . lineno if @token . respond_to? ( :lineno ) )
54- super ( message . to_s )
73+ super ( message . to_s , code : options . fetch ( :code , 400 ) )
5574 end
5675 end
5776 end
0 commit comments