Skip to content

Commit 4c25900

Browse files
committed
Add a new exception type for the benefit of consumers
1 parent 656fef5 commit 4c25900

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

app/controllers/api/notes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def create
8989
lat = OSM.parse_float(params[:lat], OSM::APIBadUserInput, "lat was not a number")
9090
description = params[:text]
9191

92-
raise OSM::APIAccessDenied if current_user.nil? && GeoblockZone.falls_within_any?(:lon => lon, :lat => lat)
92+
raise OSM::APIProtectedZoneError if current_user.nil? && GeoblockZone.falls_within_any?(:lon => lon, :lat => lat)
9393

9494
# Get note's author info (for logged in users - user_id, for logged out users - IP address)
9595
note_author_info = author_info

lib/osm.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ def status
1919

2020
# Raised when access is denied.
2121
class APIAccessDenied < APIError
22-
def initialize
23-
super("Access denied")
22+
def initialize(message = "Access denied")
23+
super
24+
end
25+
26+
def status
27+
:forbidden
28+
end
29+
end
30+
31+
class APIProtectedZoneError < APIAccessDenied
32+
def initialize(message = "Attempted to edit a Protected Zone without enough trust")
33+
super
2434
end
2535

2636
def status

0 commit comments

Comments
 (0)