diff --git a/applications/crossbar/src/modules_v1/cb_devices_v1.erl b/applications/crossbar/src/modules_v1/cb_devices_v1.erl index 708979244e9..235a6c5502d 100644 --- a/applications/crossbar/src/modules_v1/cb_devices_v1.erl +++ b/applications/crossbar/src/modules_v1/cb_devices_v1.erl @@ -152,19 +152,24 @@ validate_device(Context, DeviceId, ?HTTP_DELETE) -> -spec post(cb_context:context(), path_token()) -> cb_context:context(). post(Context, DeviceId) -> - _ = kz_util:spawn(fun crossbar_util:flush_registration/1, [Context]), case changed_mac_address(Context) of 'true' -> - _ = crossbar_util:maybe_refresh_fs_xml('device', Context), Context1 = cb_modules_util:take_sync_field(Context), Context2 = crossbar_doc:save(Context1), - _ = maybe_aggregate_device(DeviceId, Context2), - _ = kz_util:spawn( - fun() -> - _ = provisioner_util:maybe_provision(Context2), - _ = provisioner_util:maybe_sync_sip_data(Context1, 'device') - end), - Context2; + case cb_context:resp_status(Context2) of + 'success' -> + _ = kz_util:spawn(fun crossbar_util:flush_registration/1, [Context2]), + _ = crossbar_util:maybe_refresh_fs_xml('device', Context2), + _ = maybe_aggregate_device(DeviceId, Context2), + _ = kz_util:spawn(fun() -> + _ = provisioner_util:maybe_provision(Context2), + _ = provisioner_util:maybe_sync_sip_data(Context2, 'device') + end + ), + Context2; + _ -> + Context2 + end; 'false' -> error_used_mac_address(Context) end. @@ -190,12 +195,17 @@ put(Context, DeviceId) -> -spec delete(cb_context:context(), path_token()) -> cb_context:context(). delete(Context, DeviceId) -> - _ = crossbar_util:refresh_fs_xml(Context), Context1 = crossbar_doc:delete(Context), - _ = crossbar_util:flush_registration(Context), - _ = kz_util:spawn(fun provisioner_util:maybe_delete_provision/1, [Context]), - _ = maybe_remove_aggregate(DeviceId, Context), - Context1. + case cb_context:resp_status(Context) of + 'success' -> + _ = crossbar_util:flush_registration(Context1), + _ = crossbar_util:refresh_fs_xml(Context1), + _ = kz_util:spawn(fun provisioner_util:maybe_delete_provision/1, [Context1]), + _ = maybe_remove_aggregate(DeviceId, Context1), + Context1; + _ -> + Context1 + end. %%%============================================================================= %%% Internal functions